jsr包:
import org.json.JSONArray;
import org.json.JSONObject;
public static void main(String[] args) {
/* String JsonStr = "{"error":0,"data":{"src":"http:/\/v.dezhi.com\/content\/xml\/59c32550a7764.xml"},"time":0}";*/
String JsonStr = "{object:{persons:" +
??????????"[{src:‘呵呵‘,image:‘http://10.0.159.132:8080/Web/s1.png‘}," +
????????????"{src:‘哈哈‘,image:‘http://10.0.159.132:8080/Web/s1.png‘}," +
????????????"{src:‘嘿嘿‘,image:‘http://10.0.159.132:8080/Web/s2.jpg‘}]}}";
JSONObject jsonObj=new JSONObject(JsonStr);
???????//通过属性名,获得内部的对象
????????JSONObject jsonPersons=jsonObj.getJSONObject("object");
???????//获得json对象组
???????JSONArray arr=jsonPersons.getJSONArray("persons");
????????for(int i=0;i<arr.length();i++){
????????????//循环对象,并通过getString("属性名");来获得值
??????????JSONObject tempJson=arr.getJSONObject(i);
??????????
????????????System.out.print(tempJson.getString("src"));
???????????System.out.println(tempJson.getString("image"));
}
}
json解析学习
原文地址:http://www.cnblogs.com/tongyl/p/7567446.html