String json = "{''data'':[{''name'':''Wallace''},{''name'':''Grommit''}]}"; StringBuffer marketXml = new StringBuffer(); jsonObjSplit = new JSONObject(json ); JSONArray ja = jsonObjSplit.getJSONArray("data'"); for (int i = 0; i < ja.length(); i++) { JSONObject jo = (JSONObject) ja.get(i); marketXml.append(jo.get(''name'")); System.out.println(marketXml.toString()); } -------------------------------------------------------------------------遍历json 对象 jsonObj = new JSONObject(activeMarketRet); for (Iterator iter = jsonObj.keys(); iter.hasNext();) { //先遍历整个 people 对象 String key = (String)iter.next(); System.out.println(jsonObj .getString(Key)); }
本文介绍了一种使用Java解析并遍历JSON数据的方法。通过示例代码展示了如何从JSON字符串中提取特定字段的值,并将这些值拼接到StringBuffer中进行后续处理。此外,还演示了如何遍历整个JSON对象。
756

被折叠的 条评论
为什么被折叠?



