org.json package
- JSON is a light-weight,language independent,data interchange format.
- org.json package implement JSON encoders/decoders in Java.It also includes the cpability to convert between JSON and XML,HTTP headers,Cookies and CDL.
- This is a reference implementation.
- The package compiles on Java 1.6-1.8
- JSONObject.java:The JSONObject can parse text from a String or a JSONTokener to produce a map-like object.The object provides methods for manipulating its contents,and for producing a JSON compliant object serialization.
public JSONObject();
public JSONObject(JSONObject jo, String[] names);
public JSONObject(JSONTokener x) throws JSONException ;
public JSONObject(Map<?, ?> m);
public JSONObject(Object bean);
public JSONObject(Object object, String names[]);
public JSONObject(String source) throws JSONException;
public JSONObject(String baseName, Locale locale) throws JSONException;
- JSONArray.java:The JSONArray can parse text from a String or a JSONTokener to produce a vector-like object.The object provides methods for manipulating its contents,and for producing a JSON compliant array serialization.
public JSONArray() {
this.myArrayList = new ArrayList<Object>();
}
public JSONArray(JSONTokener x) throws JSONException;
public JSONArray(String source) throws JSONException;
public JSONArray(Collection<?> collection);
public JSONArray(Object array) throws JSONException;
- JSONTokener.java:The JSONTokener breaks a text into a sequence of individual tokens.It can be constructed from String,Reader,or InputStream.
public JSONTokener(Reader reader);
public JSONTokener(InputStream inputStream);
public JSONTokener(String s);
- JSONException.java: The JSONException is the standard exception type thrown by this package.
public class JSONException extends RuntimeException{
public JSONException(final String message) {
super(message);
}
public JSONException(final String message, final Throwable cause) {
super(message, cause);
}
public JSONException(final Throwable cause) {
super(cause.getMessage(), cause);
}
}
- Cookie.java: Cookie provides support for converting between JSON and cookies.
public static JSONObject toJSONObject(String string) throws JSONException {
String name;
JSONObject jo = new JSONObject();
Object value;
JSONTokener x = new JSONTokener(string);
jo.put("name", x.nextTo('='));
x.next('=');
jo.put("value", x.nextTo(';'));
x.next();
while (x.more()) {
name = unescape(x.nextTo("=;"));
if (x.next() != '=') {
if (name.equals("secure")) {
value = Boolean.TRUE;
} else {
throw x.syntaxError("Missing '=' in cookie parameter.");
}
} else {
value = unescape(x.nextTo(';'));
x.next();
}
jo.put(name, value);
}
return jo;
}
- CookieList.java: CookieList provides support for converting between JSON and cookie lists.
public static JSONObject toJSONObject(String string) throws JSONException {
JSONObject jo = new JSONObject();
JSONTokener x = new JSONTokener(string);
while (x.more()) {
String name = Cookie.unescape(x.nextTo('='));
x.next('=');
jo.put(name, Cookie.unescape(x.nextTo(';')));
x.next();
}
return jo;
}
- HTTP.java: HTTP provides support for converting between JSON and HTTP headers.
public static JSONObject toJSONObject(String string) throws JSONException {
JSONObject jo = new JSONObject();
HTTPTokener x = new HTTPTokener(string);
String token; token = x.nextToken();
if (token.toUpperCase(Locale.ROOT).startsWith("HTTP")) { // Response jo.put("HTTP-Version", token);
jo.put("Status-Code", x.nextToken());
jo.put("Reason-Phrase", x.nextTo('\0'));
x.next(); } else { // Request jo.put("Method", token);
jo.put("Request-URI", x.nextToken());
jo.put("HTTP-Version", x.nextToken());
} // Fields while (x.more()) {
String name = x.nextTo(':');
x.next(':');
jo.put(name, x.nextTo('\0'));
x.next();
}
return jo;
}
- XML.java: XML provides support for converting between JSON and XML.
org.json package的更多相关文章
- golang基础知识之encoding/json package
golang基础知识之json 简介 JSON(JavaScript Object Notation)是一种轻量级的数据交换格式.可以去json.org 查看json标准的清晰定义.json pack ...
- nodejs package.json详细解读
package.json详细内容 它是这样一个json文件(注意:json文件内是不能写注释的,复制下列内容请删除注释): JavaScript { "name": "t ...
- 详解vue-cli脚手架项目-package.json
该随笔收藏自: 详解vue-cli脚手架项目-package.json package.json是npm的配置文件,里面设定了脚本以及项目依赖的库. npm run dev 这样的命令就写在packa ...
- Node.js学习笔记(三) --- package.json 及cnpm
一.包 Nodejs 中除了它自己提供的核心模块外,我们可以自定义模块,也可以使用第三方的模块.Nodejs 中第三方模块由包组成,可以通过包来对一组具有相互依赖关系的模块进行统一管理. 完全符合 ...
- npm和package.json那些不为常人所知的小秘密
此文已由作者黄锴授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 强大的命令功能 如果你没使用过script,那你可算是从来没手动编辑过package.json.script作 ...
- package.json详解
1.概念 Node.js项目遵循模块化的架构,当我们创建了一个Node.js项目,意味着创建了一个模块,这个模块的描述文件,被称为package.json 亦即:模块的描述文件 = package.j ...
- Nodejs 包与 npm第三方模块安装和 package.json 以及 cnpm
包与 NPM 1. 包 Nodejs 中除了它自己提供的核心模块外,可以自定义模块,也可以使用第三方的模块.Nodejs 中第三方模块由包组成,可以通过包来对一组具有相互依 赖关系的模块进行统一管理. ...
- package.json文件配置说明
1.什么是package.json package.json文件是Node.js项目中的一个描述文件,执行npm init命令初始化项目后,在项目的根目录下自动生成该文件.package.json包含 ...
- 【转】Struts2中json插件的使用
配置注意点: 在原有Struts2框架jar包的引入下,需要额外多加一个Json的插件包(struts2-json-plugin-2.3.7.jar) 在struts.xml配置文件中,包需要继承js ...
随机推荐
- SpringBoot 指定资源文件的位置
SpringBoot默认的存放静态资源文件的位置是在: 里面的. 注:SpringBoot中的src/main/resources/资源文件夹对应classpath:. 默认存放静态资源文件的位置,在 ...
- 基于Intel OpenVINO的搭建及应用,包含分类,目标检测,及分割,超分辨
PART I: 搭建环境OPENVINO+Tensorflow1.12.0 I: l_openvino_toolkit_p_2019.1.094 第一步常规安装参考链接:https://docs.op ...
- [LeetCode] 55. Jump Game 跳跃游戏
Given an array of non-negative integers, you are initially positioned at the first index of the arra ...
- java ++和--
public class Sample { public static void main(String[] args) { , num2 = ; , num4 = ; System.out.prin ...
- 【洛谷】P4594 [COCI2011-2012#5] BLOKOVI
本来已经有一个专门记录洛谷题目的博客了,但这个题之毒瘤...... 为你专门写一篇总行了吧...... 传送门 先说一句,这个题每次摆放都靠到最右边不一定是最优的 因为它可以这个亚子 就是说上面那个块 ...
- qt no doubments matching "ui..h" could be found
问题情境描述: 自己单独添加的UI文件,然后添加一个类来使用这个UI文件,第一次输入UI Form名称时是大写,被添加到工程里面就是大写, 大写的情况下,添加action转到槽就会提示这个错误. 修改 ...
- windows 排查javaWeb程序占用CPU过高问题(可追踪到问题代码所在行)
1.情景展示 java虚拟机占用这么高的CPU,肯定不正常! 2.原因分析 第一个是tomcat,正在运行java项目: 第二个是eclipse,因为eclipse的运行依赖于java. 现在的问 ...
- $ is not defined与SpringMVC访问静态资源
编写前台Jquery代码时,遇到谷歌浏览器报错:Uncaught ReferenceError: $ is not defined 意味着Jquery库并没有导入到页面.这是有几种情况需要考虑: 1. ...
- POJ 1146 ID Codes 用字典序思想生成下一个排列组合
ID Codes Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 7644 Accepted: 4509 Descript ...
- Spring Boot 自定义 Shiro 过滤器,无法使用 @Autowired 解决方法
在 Spring Boot 中集成 Shiro,并使用 JWT 进行接口认证. 为了统一对 Token 进行过滤,所以自定义了一个 JwtTokenFilter 过滤器. 期间遇到了以下几个问题,这里 ...