例一。(org.json包)
首先导入org.json下面的包
package com.sun;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class Test {
public static void main(String args[]) throws JSONException {
String jsonContent = "{'hello':world,'abc':'xyz'}";
JSONObject jsonObject = new JSONObject(jsonContent);
String str1 = jsonObject.getString("hello");
String str2 = jsonObject.getString("abc");
System.out.println(str1);
System.out.println(str2);
System.out.println("------------------");
jsonContent = "[{'hello':333,'abc':'false','xyz':{'a':1,'b':'ab'}},{'hello':555,'abc':'true','xyz':{'a':2,'b':'ba'}}]";
JSONArray jsonArray = new JSONArray(jsonContent);
for(int i=0;i<jsonArray.length();i++){
JSONObject jsonobject2=jsonArray.getJSONObject(i);
int value1=jsonobject2.getInt("hello");
boolean value2=jsonobject2.getBoolean("abc");
// String value3=jsonobject2.getString("xyz");
JSONObject jsonobject3=jsonobject2.getJSONObject("xyz");
int value4=jsonobject3.getInt("a");
String value5=jsonobject3.getString("b");
System.out.println(value1);
System.out.println(value2);
System.out.println(value4);
System.out.println(value5);
}
}
}
输出结果
world
xyz
------------------
333
false
1
ab
555
true
2
ba
分享到:
相关推荐
Java下的json构造和解析工具包:org.json.jar,轻量级,且它还包含JSON与XML, HTTP headers, Cookies, CDL的转换。
org.json.JSONObect的一个jar包org.json.JSONObect的一个jar包
org.json.JSONObject的6个jar包 commons-beanutils;commons-collections;commons-lang;commons-logging;ezmorph;json-lib
Java中使用Json的net.sf.json包,其中包含JSONObject与JSONArray等操作类,十分好用。
org.json.JSONObject引用依赖包
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...
org.json最新版本jar包(2017.10.18)
org.json的依赖包
JSON net.sf.json 依赖的jar包 亲测可用 一次导入所有jar包
org.json的json包文件,只是没有提供javabean直接转化json和json转化javabean,在此基础上添加JSONUtil类,提供了这两个方法,暂时不全希望大家谅解。
net.sf.json.JSONArray等JSON类所需要的jar包组合。包括JSONObject等
这个jar包可以实现xml与json字符串互相转化的功能。通过常我们反序列化时都习惯用json,但有些接口仍然使用xml,那么可以借助这个工具来实现xml转换json了。
net.sf.json.JSONObject相关jar包
org.json库的源代码,在java中操作json串的库,轻量级库。
使用json.org.jar包,解析json文件,比较简洁明了,该资源是一个android小DEMO
eclipse中使用json相关的jar包,比较全,有gson相关的。
JAVA操作JSON的全套工具包,无需另外下载包括标签中的全部包令外包括其他两个,标签写不下了
使用Java操作JSON字符串对象,使用Java操作JSON字符串对象
org.json java处理json数据 包含source class文件和 javadoc