首页 > 技术文章 > JSONObject与JSONArray的使用

sysout 2016-02-02 16:02 原文

maven: json-lib

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

 

{"id":"J_10058164","p":"71.30","m":"108.00"}

解析JSON字符串

JSONObject obj = JSONObject.fromObject(jsonString);  //将Json字符串转为java对象

System.out.println(obj.getString("p")); //获取Object中的p  ->输出1.30

JSONArray transitListArray = obj.getJSONArray("Array");  //获取Object中的Array

 

遇到的问题:

install的时候总是说找不到这个jar

解决办法:加一行

<classifier>jdk15</classifier>

  

参考资料

http://blog.csdn.net/rambo_china/article/details/7691409

http://blog.csdn.net/initphp/article/details/9222731

推荐阅读