首页 > Web开发 > 详细

json解析学习

时间:2017-09-21 12:30:32      阅读:176      评论:0      收藏:0      [点我收藏+]

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!