json文件比如下面:
[
{
"name":"sheep", "age":"20"
},
{
"name":"monkey","age":"30"
}
]
json org
这里有关于json很多资料,包括一大堆java的json库。。
json-lib,这也是一个,可以试试。
http://json-lib.sourceforge.net/index.html
fastjson一个易于使用,性能卓越的JSON处理工具:
http://www.oschina.net/p/fastjson
https://github.com/alibaba/fastjson
反序列化为JSONObject对象
String text = ...; // 例如 {"name":"张老头", "age":66}
JSONObject json = JSON.parseObject(text);
我用的 org.json. ,android 上也带的有
package com.example;
import org.json.JSONArray;
import org.json.JSONObject;
public class MyClass {
public static void main (String []args){
String data = "[{\"name\":\"sheep\", \"age\":\"20\"}, {\"name\":\"monkey\",\"age\":\"30\"}]";
JSONArray jsonArray = new JSONArray(data);
JSONObject first = jsonArray.getJSONObject(0);
String value = first.getString("age");
System.out.println(value);
}
}
推荐Google发布的json库:Gson
https://code.google.com/p/google-gson/
当然是官方的了:
http://json.org/java/
https://github.com/douglascrockford/JSON-java
不过github上没.jar文件,需要自己export