JSON 详解

JSON 详解

1) 官网:http://www.json.org/

2) json-lib.jar开发包

2.1下载地址:http://json-lib.sourceforge.net/ 

2.2 依赖包:

commons-beanutils.jar;
commons-httpclient.jar;
commons-lang.jar;
ezmorph.jar;
morph-1.0.1.jar;

示例

		String jsonString = "{'total':20,'data':[{'name':'Tom','age':16},{'name':'Kate','age':20}]}";
		
		JSONObject object = JSONObject.fromObject(jsonString);
		System.out.println(object.get("total"));
		
		JSONArray array = (JSONArray)object.get("data");
		
		JSONObject obj1 = (JSONObject)array.get(0);
		JSONObject obj2 = (JSONObject)array.get(1);
		
		System.out.println(obj1.get("name"));
		System.out.println(obj2.get("age"));


相关链接: 
http://ezmorph.sourceforge.net/ 
http://morph.sourceforge.net/ 

猜你喜欢

转载自ihuning.iteye.com/blog/2211985