Java:JSON解析工具-org.json
一、简介
org.json是Java常用的Json解析工具,主要提供JSONObject和JSONArray类,现在就各个类的使用解释如下。
二、准备
1.在使用org.json之前,我们应该先从该网址https://github.com/douglascrockford/JSON-java下载org.json源码,并将源码其加入到Eclipse中,即可调用。
2.查看相关的API文档,访问:https://github.com/douglascrockford/JSON-java。
https://github.com/stleary/JSON-Java-unit-test
三、讲解:
1.JSONObject:
是一个无序的键/值对集合。
它的表现形式是一个包裹在花括号的字符串,键和值之间使用冒号隔开,键值和键值之间使用逗号隔开。
内在形式是一个使用get()和opt()方法通过键来访问值,和使用put()方法通过键来添加或者替代值的对象。
值可以是任何这些类型:Boolean,JSONArray,JSONObject,Number和String,或者JOSONObject.NULL对象。
代码演示如下:
- public static void jsonObjectTest() {
- ᅠ ᅠ JSONObject jsonobj = new JSONObject("{'name':'xiazdong','age':20}");
- String name = jsonobj.getString("name");
- ᅠ ᅠ int age = jsonobj.getInt("age");
- System.out.println("name = " + name + ",age = " + age);
- }
注:JSONObject有很多optXXX方法,比如optBoolean, optString, optInt...
他们的意思是,如果这个jsonObject有这个属性,则返回这个属性,否则返回一个默认值。
2.JSONArray:
是一个有序的序列值。
它的表现形式是一个包裹在方括号的字符串,值和值之间使用逗号隔开。
内在形式是一个使用get()和opt()方法通过索引来访问值,和使用put()方法来添加或修改值的对象。
值可以是任何这些类型:Boolean,JSONArray,JSONObject,Number,和String,或者JSONObject.NULL对象。
代码演示如下:
- public static void jsonArrayTest() {
- ᅠ ᅠ JSONArray jsonarray = new JSONArray("[{'name':'xiazdong','age':20},{'name':'xzdong','age':15}]");
- ᅠ ᅠ for (int i = 0; i < jsonarray.length(); i++) {
- ᅠ ᅠ ᅠ ᅠᅠJSONObject jsonobj = jsonarray.getJSONObject(i);
- String name = jsonobj.getString("name");
- int age = jsonobj.getInt("age");
- System.out.println("name = " + name + ",age = " + age);
- }
- }
嵌套的JSONObject和JSONArray代码演示如下:
- public static void jsonObjectAndArrayTest() {
- ᅠ ᅠ String jsonstring = "{'name':'xiazdong','age':20,'book':['book1','book2']}";
- ᅠ ᅠ JSONObject jsonobj = new JSONObject(jsonstring);
- String name = jsonobj.getString("name");
- ᅠ ᅠ System.out.println("name" + ":" + name);
- int age = jsonobj.getInt("age");
- System.out.println("age" + ":" + age);
- ᅠ ᅠ JSONArray jsonarray = jsonobj.getJSONArray("book");
- ᅠ ᅠ for (int i = 0; i < jsonarray.length(); i++) {
- String book = jsonarray.getString(i);
- ᅠ ᅠ ᅠ ᅠ System.out.println("book" + i + ":" + book);
- }
- }
3.JSONStringer:
是一个用于快速构造JSON文本的工具
JSONWriter的子类
bject():开始一个对象,即添加{;enObject():结束一个对象,即添加}
array():开始一个数组,即添加[; endArray():结束一个数组,即添加]
key():表示添加一个key;value():表示添加一个value
代码演示如下:
- public static void jsonStringerTest() {
- ᅠ ᅠ JSONStringer stringer = new JSONStringer();
- stringer.object().key("name").value("xiazdong").key("age").value(20).endObject();
- ᅠ ᅠ System.out.println(stringer);
- }
负载的JSON格式写演示(PrintWriter+JSONStringer可以写入JSON文件):
- public static void jsonStringerTest2() throws FileNotFoundException {
- ᅠ ᅠ JSONStringer jsonStringer = new JSONStringer();
- ᅠ ᅠ JSONObject obj6 = new JSONObject();
- obj6.put("title", "book1").put("price", "$11");
- ᅠ ᅠ JSONObject obj3 = new JSONObject();
- obj3.put("book", obj6);
- ᅠ ᅠ obj3.put("author", new JSONObject().put("name", "author-1"));
- ᅠ ᅠ JSONObject obj5 = new JSONObject();
- obj5.put("title", "book2").put("price", "$22");
- ᅠ ᅠ JSONObject obj4 = new JSONObject();
- obj4.put("book", obj5);
- ᅠ ᅠobj4.put("author", new JSONObject().put("name", "author-2"));
- ᅠ ᅠ JSONArray obj2 = new JSONArray();
- obj2.put(obj3).put(obj4);
- ᅠ ᅠ JSONObject obj1 = new JSONObject();
- obj1.put("title", "BOOK");
- obj1.put("signing", obj2);
- jsonStringer.object().key("session").value(obj1).endObject();
- System.out.println(jsonStringer.toString());
- ᅠ ᅠ PrintWriter out = new PrintWriter(new FileOutputStream("1.txt"));
- ᅠ ᅠ out.println(jsonStringer.toString());
- out.close();
- }
4.JSONTokener
它和JSONObject和JSONArray的构造函数一起使用,用于解析JSON源字符串
代码演示如下(JSONObject+JSONTokener能够获取JSON格式文本对象):
- public static void JSONTokenerTest() throws FileNotFoundException {
- JSONObject jsonobj = new JSONObject(new JSONTokener(new FileReader(new File("1.txt"))));
- System.out.println(jsonobj.getJSONObject("session").getJSONArray("signing").getJSONObject(1).getJSONObject("book").getString("title"));
- }
注意:在Java中,JSON格式的字符串最好用单引号表示
JSON in Java [package org.json] JSON is a light-weight, language independent, data interchange format.
See http://www.JSON.org/ The files in this package implement JSON encoders/decoders in Java.
It also includes the capability to convert between JSON and XML, HTTP
headers, Cookies, and CDL. This is a reference implementation. There is a large number of JSON packages
in Java. Perhaps someday the Java community will standardize on one. Until
then, choose carefully. The license includes this restriction: "The software shall be used for good,
not evil." If your conscience cannot live with that, then choose a different
package. 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. JSONArray.java: The JSONObject 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. JSONTokener.java: The JSONTokener breaks a text into a sequence of individual
tokens. It can be constructed from a String, Reader, or InputStream. JSONException.java: The JSONException is the standard exception type thrown
by this package. JSONPointer.java: Implementation of
[JSON Pointer (RFC 6901)](https://tools.ietf.org/html/rfc6901). Supports
JSON Pointers both in the form of string representation and URI fragment
representation. JSONString.java: The JSONString interface requires a toJSONString method,
allowing an object to provide its own serialization. JSONStringer.java: The JSONStringer provides a convenient facility for
building JSON strings. JSONWriter.java: The JSONWriter provides a convenient facility for building
JSON text through a writer. CDL.java: CDL provides support for converting between JSON and comma
delimited lists. Cookie.java: Cookie provides support for converting between JSON and cookies. CookieList.java: CookieList provides support for converting between JSON and
cookie lists. HTTP.java: HTTP provides support for converting between JSON and HTTP headers. HTTPTokener.java: HTTPTokener extends JSONTokener for parsing HTTP headers. XML.java: XML provides support for converting between JSON and XML. JSONML.java: JSONML provides support for converting between JSONML and XML. XMLTokener.java: XMLTokener extends JSONTokener for parsing XML text. Unit tests are maintained in a separate project. Contributing developers can test
JSON-java pull requests with the code in this project:
https://github.com/stleary/JSON-Java-unit-test
package com.json; import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map; import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject; /**
* 使用json-lib构造和解析Json数据
*
* @author Alexia
* @date 2013/5/23
*
*/
public class OrgJsonTest { /**
* 构造Json数据
*
* @return
* @throws JSONException
*/
public static String BuildJson() throws JSONException { // JSON格式数据解析对象
JSONObject jo = new JSONObject(); // 下面构造两个map、一个list和一个Employee对象
Map<String, String> map1 = new HashMap<String, String>();
map1.put("name", "Alexia");
map1.put("sex", "female");
map1.put("age", "23"); Map<String, String> map2 = new HashMap<String, String>();
map2.put("name", "Edward");
map2.put("sex", "male");
map2.put("age", "24"); List<Map> list = new ArrayList<Map>();
list.add(map1);
list.add(map2); Employee employee = new Employee();
employee.setName("wjl");
employee.setSex("female");
employee.setAge(24); // 将Map转换为JSONArray数据
JSONArray ja = new JSONArray();
ja.put(map1); System.out.println("JSONArray对象数据格式:");
System.out.println(ja.toString()); // 将Javabean转换为Json数据(需要Map中转)
JSONObject jo1 = JsonHelper.toJSON(employee); System.out.println("\n仅含Employee对象的Json数据格式:");
System.out.println(jo1.toString()); // 构造Json数据,包括一个map和一个含Employee对象的Json数据
jo.put("map", ja);
jo.put("employee", jo1.toString());
System.out.println("\n最终构造的JSON数据格式:");
System.out.println(jo.toString()); return jo.toString(); } /**
* 解析Json数据
*
* @param jsonString
* Json数据字符串
* @throws JSONException
* @throws ParseException
*/
public static void ParseJson(String jsonString) throws JSONException,
ParseException { JSONObject jo = new JSONObject(jsonString);
JSONArray ja = jo.getJSONArray("map"); System.out.println("\n将Json数据解析为Map:");
System.out.println("name: " + ja.getJSONObject(0).getString("name")
+ " sex: " + ja.getJSONObject(0).getString("sex") + " age: "
+ ja.getJSONObject(0).getInt("age")); String jsonStr = jo.getString("employee");
Employee emp = new Employee();
JsonHelper.toJavaBean(emp, jsonStr); System.out.println("\n将Json数据解析为Employee对象:");
System.out.println("name: " + emp.getName() + " sex: " + emp.getSex()
+ " age: " + emp.getAge()); } /**
* @param args
* @throws JSONException
* @throws ParseException
*/
public static void main(String[] args) throws JSONException, ParseException {
// TODO Auto-generated method stub ParseJson(BuildJson());
} }
运行结果如下
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA8cAAAEICAIAAAD9TBFFAAAgAElEQVR4nO3d26HiIBRG4dRFQdRDNTSTYjIPuXHZm0AgUc+s72HGkwsBovEXUacFAAAAQJ/p0xUAAAAAfh6pGgAAAOj1v6fqaRJ6QFxYufvYAut3PDZu2gUAAABD/O8JTIzFInGvwg1t+8qSC6VdtoVgDQAA8LL/In51ptjCwnx4+DJVlwvP/xSrLSJMAwAAfMp/l8OOHJxHbW2UOo+2lavEP8X65GUuelivqWd+IAAAADwnz17eRtnM+mVZlsWZfYExdl8YL3fhEuPmZVnmY7VxUcn7xu+bWsaqL/9M8uukjElr0TmPv0kJWhavaRoAAABeo+aw2ZkjO3u7peRlC8pB1N43mp2Jg3Wwd5ihZ2es9/Yo7w1a2M2X1A8Ai6m3JlVrh66sYQGpGgAA4FOaU3W0RTzk7PdB7DU477k6StXbYh+Od2+D2MbN+2j2djRteTzqPcfFbEuOP7Z21sXfqGsqViWD0PmBCocTA3Qhu4tbhtuXK0zmBgAAeE5Vql6kmR6zM2nU3oeg11339WGqPtJ0HKuXPQXvQdz74vJgvTNBQXGpcQvkpKsNGOdrK0eRtVR9LC8MgReiec3ANqkaAADgU8KkFQ0qJ6k6XL4G68tUvQ9mB8UGqTctX5sUIi6P537H6f8cz052vBwGFod+Cyk5j8X59oXh5HLKF0N8OUaTmwEAA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n5aqicVHHCuOcPWs04rzndQgPvbWJVA0AAL5MPFbtbRibzzTj/RFhzlkX6/v08/l+/TGnIdw1nabRkK7iQco0X2mLGlJ1uOXa9L2NSv33Jq+tiNrQmhqlsWr5uHo/y+dFat1FuzRK+fF94Gz0oPMetyF+5XLeO0nVAADgm2Sp+ggrye18aHVPNkfW2faIx5KneyOUy7Isy3oAZ9a8K01E7kvVccOkgfa8/tva7rkVearWjqv186Kcl+gI83X5BcXzfpaaD1T3nffg6FELkjH+H53fAgAA/qSKVB2PF56bFFL1oBnD3ho3e2u9t8Z5aXiyN1VHRZ2TLvT6H9GxN9KJqVo8bunVi3ReovLm5O+2GhbPe7pi6Ezx/M2AdDVj1QAA4JvUpep4bvFFqpZmI5yaZgJ4a601bl5HKYUg25eqow2PVK3XP/xuin0uSLiuZXRWngGifKfJ5asXKYRKM0BaRo/18sOCwxWjzns4GyefCLSVRqoGAADfJPu04pp8wtvxh9aSz81N1m8fqHOzt9IeU/zBtab0OZ/ZVY7KUapOPwR4eZR4ykIyAJvWfz5bLH0h9JBPK+bHnUv9LJyXvPOjA+jn5aKeYfnRZA9jTKn+h6b59En10+n1x2JmgAAAgG/x49+sJ41V41WPf+82AADAD/jtVP27X8n8Z3jLmDEAAMBPpuroW5Q/XZn/U3AKGKgGAAD4zVQNAAAAfBdSNQAAANCLVA0AAAD0IlUDAAAAvUjVAAAAQC9SNQAAANCLVA0AAAD0IlUDAAAAvUjVAAAAQC9SNQAAANCLVA0AAAD0IlUDAAAAvf4BoH6PlCEq9wcAAAAASUVORK5CYII=" alt="" />
五、与json-lib比较
json-lib和org.json的使用几乎是相同的,我总结出的区别有两点:
1. org.json比json-lib要轻量得多,前者没有依赖任何其他jar包,而后者要依赖ezmorph和commons的lang、logging、beanutils、collections等组件
2. json-lib在构造bean和解析bean时比org.json要方便的多,json-lib可直接与bean互相转换,而org.json不能直接与bean相互转换而需要map作为中转,若将bean转为json数据,首先需要先将bean转换为map再将map转为json,比较麻烦。
总之,还是那句话—适合自己的才是最好的,大家要按需选取使用哪种方法进行解析。最后给大家介绍两款解析Json数据的工具:一是在线工具JSON Edit(http://braincast.nl/samples/jsoneditor/);另一个是Eclipse的插件JSON Tree Analyzer,都很好用,推荐给大家使用!
http://www.cnblogs.com/lanxuezaipiao/archive/2013/05/24/3096437.html
Java:JSON解析工具-org.json的更多相关文章
- JSON解析工具-org.json使用教程
转自:http://www.open-open.com/lib/view/open1381566882614.html 一.简介 org.json是Java常用的Json解析工具,主要提供JSONO ...
- JSON 解析工具的封装(Java)
JSON 解析工具的封装(Java) 一直想有一个属于自己的JSON工具,今天终于弄好了..... 1.添加pom依赖包 <!--json解析--> <dependency> ...
- java后台常用json解析工具问题小结
若排版紊乱可查看我的个人博客原文地址 java后台常用json解析工具问题小结 这里不细究造成这些问题的底层原因,只是单纯的描述我碰到的问题及对应的解决方法 jackson将java对象转json字符 ...
- Json解析工具Jackson(使用注解)
原文http://blog.csdn.net/nomousewch/article/details/8955796 接上一篇文章Json解析工具Jackson(简单应用),jackson在实际应用中给 ...
- 自定义Json解析工具
此博客为博主原创文章,转载请标明出处,维权必究:https://www.cnblogs.com/tangZH/p/10689536.html fastjson是很好用的json解析工具,只可惜项目中要 ...
- JSON解析工具比较,主要GSON和FastJSON
JSON解析工具比较,主要GSON和FastJSON 一 .各个JSON技术的简介和优劣 1.json-lib json-lib最开始的也是应用最广泛的json解析工具,json-lib 不好的地方确 ...
- [转] 各种Json解析工具比较 - json-lib/Jackson/Gson/FastJson
JSON技术的调研报告 一 .各个JSON技术的简介和优劣1.json-libjson-lib最开始的也是应用最广泛的json解析工具,json-lib 不好的地方确实是依赖于很多第三方包,包括com ...
- Gson json解析工具
json 解析工具 ,谷歌出品 对象转换字符串 HashMap<String,String> hashMap = new HashMap<String, String>(); ...
- Json解析工具Jackson(使用注解)--jackson框架自定义的一些json解析注解
Json解析工具Jackson(使用注解)--jackson框架自定义的一些json解析注解 @JsonIgnoreProperties 此注解是类注解,作用是json序列化时将Javabean中的一 ...
随机推荐
- [D3] Create DOM Elements with D3 v4
Change is good, but creating from scratch is even better. This lesson shows you how to create DOM el ...
- Iceberg使用
Iceberg是Mac下比較好用的pkg生成工具. 在files中选择你想要存放(自己文件的目录),生成pkg后目录就会存储在设置的那个目录下. 点击scripts选择pkg安装各个阶段所要运行脚本路 ...
- Android ---------- Android Bar Bug 总结
1 怎样设置 ActionBar的Tab 的颜色? // 设置actionBar的颜色 Drawable draw = new ColorDrawable(Color.GREEN); actionBa ...
- Css fixed和absolute定位差别
fixed:固定定位 absolute:绝对定位 差别非常easy: 1.没有滚动栏的情况下没有差异 2.在有滚动栏的情况下.fixed定位不会随滚动栏移动而移动.而absolute则会随滚动栏移动 ...
- 【例题 6-2 UVA - 514】Rails
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 栈模拟一下就好. 每个输出段后面都有一个空行. 包括最后一个. [代码] #include <bits/stdc++.h> ...
- 可视化格式模型(visual formatting model)
原文 简书原文:https://www.jianshu.com/p/7632f16ff555 大纲 1.认识可视化模型 2.可视化模型的内容 3.可视化模型的影响因素 1.认识可视化模型 盒子模型是C ...
- ZOJ 1136 Longest Ordered Subsequence DP
传送门:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1136 题目大意:给定一串序列,求最长的升序列长度,如1, 7, 3, ...
- 【BZOJ 3156】防御准备
[链接] 链接 [题意] 在这里输入题意 [题解] 把a倒过来 设f[i]表示在i放一个防御塔的最小花费; 我们如果从j转移过来 就表示j+1..i-1这一段放人偶. s[i] = 1 + 2 + . ...
- css3-11 如何实现2D动画
css3-11 如何实现2D动画 一.总结 一句话总结:就是transform属性,属性值为1.translate() 2.rotate() 3.scale(),而这是哪个属性值是带参数的 ...
- js进阶课程ajax简介(ajax是浏览器来实现的)
js进阶课程ajax简介(ajax是浏览器来实现的) 一.总结 1.ajax使用需要服务器支持,比如phpstudy 2.ajax是浏览器支持的功能:ajax有个核心对象XMLHttpRequest, ...