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
原文链接:https://www.f2er.com/json/290631.html

猜你在找的Json相关文章