當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
net.sf包JSONArray与JSONObject遍历
生活随笔
收集整理的這篇文章主要介紹了
net.sf包JSONArray与JSONObject遍历
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
//遍歷json數組
String json1 = "{data:[{name:'Wallace'},{name:'Grommit'}]}";
JSONObject jsonObjSplit = JSONObject.fromObject(json1);
JSONArray ja = jsonObjSplit.getJSONArray("data");
for (int i = 0; i < ja.size(); i++) {JSONObject jo = (JSONObject) ja.get(i);System.out.println(jo.get("name"));
}//JSONObject遍歷json對象
String json2 = "{name:'Wallace',age:15}";
jsonObj = new JSONObject(json2);for (Iterator iter = jsonObj.keys(); iter.hasNext();) {
String key = (String)iter.next();
System.out.println(jsonObj .getString(key));
}
需要用到的jar包列表:
json-lib-2.2.3-jdk15.jar
jakarta commons-lang 2.4
jakarta commons-beanutils 1.7.0
jakarta commons-collections 3.2
jakarta commons-logging 1.1.1
ezmorph 1.0.6
?
轉自:http://fatkun.com/2010/07/jsonarray-jsonobject-array.html
總結
以上是生活随笔為你收集整理的net.sf包JSONArray与JSONObject遍历的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: utf8编码-汉字几字节
- 下一篇: mysql innodb创建数据文件失败