json遍历key value

http://blog.csdn.net/lanshengsheng2012/article/details/17679487

 

public static void main(String[] args) {
String json = "{\"table\": \"viewTable\",\"data\": [{\"ctime\": \"2016-08-24 00:00:00\",\"city\": \"beijing\",\"count1\": \"1\",\"count2\": \"2\"},"+
"{\"ctime\": \"2016-08-25 00:00:00\",\"city\": \"shanghai\",\"count1\": \"4\",\"count2\": \"3\"}]}";
JSONObject jsonObject = JSONObject.fromObject(json);
String tableName = jsonObject.getString("table");
System.out.println(tableName);
JSONArray jsonArray = jsonObject.getJSONArray("data");
for(int i = 0 ;i < jsonArray.size() ; i++){
JSONObject jsonObj = JSONObject.fromObject(jsonArray.getString(i));
//http://blog.csdn.net/lanshengsheng2012/article/details/17679487
Iterator it = jsonObj.keys();
while(it.hasNext()){
String key = it.next().toString();
String value = jsonObj.getString(key);
System.out.println(key+":"+value);
}
}
}

posted @ 2016-12-07 10:32  纯粹的人  阅读(4643)  评论(0编辑  收藏  举报