• 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. koa中的路由

    原生路由 网站一般都有多个页面.通过ctx.request.path可以获取用户请求的路径,由此实现简单的路由. const main = ctx => { if (ctx.request.pa ...

  2. openLayers绘制静态底图

    由于项目需要,需要是使用openlayers框架,于是开始安利一波openlayers,可以点击 https://openlayers.org/   进入他的官网下载相关资源和案例 学习的过程总是慢慢 ...

  3. [RN] 使用 Genymotion 导致 ” Genymotion 已连接,但无法访问互联网 “ 的错误

    使用 Genymotion 导致 Genymotion 已连接,但无法访问互联网 的错误 先把要点 放前面: 网络二 一定要设置 桥接模式 网上很多文章都是设置为 NAT,笔者均失败! 笔者使用的An ...

  4. 利用mysql的LOAD DATA INFILE的功能读取客户端文件

    前言:今天在浏览某知论坛时,看到某大佬在渗透过程中使用伪造的MySQL服务端读取客户端文件,此大佬在利用过程中描述得不是很详细,作为小白的我看不懂啊,由此产生了此篇文章. 某大佬文章:https:// ...

  5. springmvc项目转为springboot

    说明 如果你的项目连maven项目都不是,请自行转为maven项目,在按照本教程进行. 本教程适用于spring+springmvc+mybatis+shiro的maven项目. 1.修改pom文件依 ...

  6. mysql中的回表查询与索引覆盖

    了解一下MySQL中的回表查询与索引覆盖. 回表查询 要说回表查询,先要从InnoDB的索引实现说起.InnoDB有两大类索引,一类是聚集索引(Clustered Index),一类是普通索引(Sec ...

  7. centos7.x下环境搭建(一)--yum方式安装mysql5.7

    前两天因为数据库被黑客攻击,导致数据被删除,数据库被损坏,系统重新安装了一下,所以环境也需要重新再搭一遍,包括mysql.nodejs.git.nginx和redis的安装.由于之前安装的mysql安 ...

  8. 『You Are Given a Tree 整体分治 树形dp』

    You Are Given a Tree Description A tree is an undirected graph with exactly one simple path between ...

  9. SSL证书格式转换

    crt格式转pem openssl x509 -in www.x.com.crt -out www.x.com.pem openssl x509 -in mycert.crt -out mycert. ...

  10. redis 缓存问题汇总

    前言:在使用redis的时候,特别是大型应用,会碰到不少问题,下面就来总结一下使用redis时的常见问题 一.redis为缓存的问题 1.缓存和数据库双写一致性问题 分析:一致性问题是分布式常见问题, ...