遍历JSONArray及JSONObject

	String json = "{''data'':[{''name'':''Wallace''},{''name'':''Grommit''}]}";

        StringBuffer marketXml = new StringBuffer();

        JSONObject 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());
        }

        JSONObject jsonObj = new JSONObject(json);
        for (Iterator iter = jsonObj.keys(); iter.hasNext();) { // 先遍历整个 people 对象
            String key = (String) iter.next();
            System.out.println(jsonObj.getString(Key));
        }

 

你可能感兴趣的:(JSONObject,JsonArray)