• 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. 每天一道Rust-LeetCode(2019-06-08)

    每天一道Rust-LeetCode(2019-06-08) 91. 解码方法 坚持每天一道题,刷题学习Rust. 题目描述 https://leetcode-cn.com/problems/decod ...

  2. JAVA基础概念(一)

    一.JAVA标识符 标识符就是用于给 Java 程序中变量.类.方法等命名的符号.如图标黄部分: 使用标识符时,需要遵守几条规则: 1.  标识符可以由字母.数字.下划线(_).美元符($)组成,但不 ...

  3. Debian 9 部分快捷键失效问题

    教程 具体修复过程: 安装gnome-screensaver包,重启恢复正常.

  4. DIV+CSS+JS实现色彩渐变字体

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  5. 第03组 Beta版本演示

    队名:不等式方程组 组长博客 组员 340 张逸杰 组长 304 苏凯婷 312 鲍冰如 320 陈荣杰 331 杨锦镔 335 王嵚 336 林家伟 341 黄彬煌 342 黄智锋 343 吴智勇 ...

  6. [POI2011]Lightening Conductor(决策单调性)

    好久没写过决策单调性了. 这题其实就是 $p_i=\lceil\max\limits_{j}(a_j-a_i+\sqrt{|i-j|})\rceil$. 拆成两边,先只考虑 $j<i$,然后反过 ...

  7. [LeetCode] 454. 4Sum II 四数之和之二

    Given four lists A, B, C, D of integer values, compute how many tuples (i, j, k, l) there are such t ...

  8. [LeetCode] 209. Minimum Size Subarray Sum 最短子数组之和

    Given an array of n positive integers and a positive integer s, find the minimal length of a contigu ...

  9. Note | PyTorch官方教程学习笔记

    目录 1. 快速入门PYTORCH 1.1. 什么是PyTorch 1.1.1. 基础概念 1.1.2. 与NumPy之间的桥梁 1.2. Autograd: Automatic Differenti ...

  10. Oracle 11g的一些常用语句记录

    一.表空间 1.创建临时表空间: create temporary tablespace project_temp tempfile 'D:\Oracle\dataspace\project_temp ...