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