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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM