• 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的更多相关文章

  1. golang基础知识之encoding/json package

    golang基础知识之json 简介 JSON(JavaScript Object Notation)是一种轻量级的数据交换格式.可以去json.org 查看json标准的清晰定义.json pack ...

  2. nodejs package.json详细解读

    package.json详细内容 它是这样一个json文件(注意:json文件内是不能写注释的,复制下列内容请删除注释): JavaScript { "name": "t ...

  3. 详解vue-cli脚手架项目-package.json

    该随笔收藏自: 详解vue-cli脚手架项目-package.json package.json是npm的配置文件,里面设定了脚本以及项目依赖的库. npm run dev 这样的命令就写在packa ...

  4. Node.js学习笔记(三) --- package.json 及cnpm

    一.包 Nodejs   中除了它自己提供的核心模块外,我们可以自定义模块,也可以使用第三方的模块.Nodejs 中第三方模块由包组成,可以通过包来对一组具有相互依赖关系的模块进行统一管理. 完全符合 ...

  5. npm和package.json那些不为常人所知的小秘密

    此文已由作者黄锴授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 强大的命令功能 如果你没使用过script,那你可算是从来没手动编辑过package.json.script作 ...

  6. package.json详解

    1.概念 Node.js项目遵循模块化的架构,当我们创建了一个Node.js项目,意味着创建了一个模块,这个模块的描述文件,被称为package.json 亦即:模块的描述文件 = package.j ...

  7. Nodejs 包与 npm第三方模块安装和 package.json 以及 cnpm

    包与 NPM 1. 包 Nodejs 中除了它自己提供的核心模块外,可以自定义模块,也可以使用第三方的模块.Nodejs 中第三方模块由包组成,可以通过包来对一组具有相互依 赖关系的模块进行统一管理. ...

  8. package.json文件配置说明

    1.什么是package.json package.json文件是Node.js项目中的一个描述文件,执行npm init命令初始化项目后,在项目的根目录下自动生成该文件.package.json包含 ...

  9. 【转】Struts2中json插件的使用

    配置注意点: 在原有Struts2框架jar包的引入下,需要额外多加一个Json的插件包(struts2-json-plugin-2.3.7.jar) 在struts.xml配置文件中,包需要继承js ...

随机推荐

  1. batch、epoch、iteration

    深度学习的优化算法,说白了就是梯度下降.每次的参数更新有两种方式. 第一种,遍历全部数据集算一次损失函数,然后算函数对各个参数的梯度,更新梯度.这种方法每更新一次参数都要把数据集里的所有样本都看一遍, ...

  2. vue中使用kindeditor富文本编辑器2

    第一步,下载依赖 yarn add kindeditor 第二步,建立kindeditor.vue组件 <template> <div class="kindeditor& ...

  3. 【Excel】截取字符 LEFT(A1,2) RIGHT(A1,2) MID(SHEET1!E2,1,9)

    LEFT(A1,2)从左边取两个字符 RIGHT(A1,2)从右边取两个字符 MID(SHEET1!E2,1,9)从sheet1表E2单元格中第一位起后9位 可以嵌套

  4. 重装系统的jdk问题???

    重装系统了!!!! 之前因为不懂电脑,然后自己动手装了台台式机,简直太开心了,又自己装了个系统,一切都非常欢乐,来到了给电脑起名字的时候,我不知道有多少人会卡在起名字这里,但是我那个时候非常开心,就想 ...

  5. github新建本地仓库并将代码提交到远程仓库

    方式一: 在github上新建好仓库:gitTest 使用命令git clone git@github.com:yourgithubID/gitTest.git,克隆到本地相应的位置 将要上传的工程代 ...

  6. 部署ComsenzDiscuz BBS论坛系统

    1.准备环节 [root@localhost ~]# unzip ComsenzDiscuz-DiscuzX-master.zip //解包 [root@localhost ~]# cd Discuz ...

  7. [LeetCode] 285. Inorder Successor in BST 二叉搜索树中的中序后继节点

    Given a binary search tree and a node in it, find the in-order successor of that node in the BST. Th ...

  8. [LeetCode] 53. Maximum Subarray 最大子数组

    Given an integer array nums, find the contiguous subarray (containing at least one number) which has ...

  9. redis持久化方式与优缺点

    Redis是一个支持持久化的内存数据库,也就是说redis需要经常将内存中的数据同步到磁盘来保证持久化.redis支持四种持久化方式,一是 Snapshotting(快照)也是默认方式:二是Appen ...

  10. Comet OJ - Contest #13-C2

    Comet OJ - Contest #13-C2 C2-佛御石之钵 -不碎的意志-」(困难版) 又是一道并查集.最近做过的并查集的题貌似蛮多的. 思路 首先考虑,每次处理矩形只考虑从0变成1的点.这 ...