JSONObject和JSONArray遍历
程序员文章站
2024-02-26 11:36:16
...
JSONObject遍历:
JSONObject jsonobject=new JSONObject(str);
Iterator iterator = jsonobject.keys();
while(iterator.hasNext()){
String key = String.valueOf(iterator.next());//得到键
String value = jsonobject.getString(key);//得到值
}
JSONArray遍历:
JSONArray jsonArray=JSONArray.fromObject(arrayStr);
Iterator<String> iterator = null;
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject item = jsonArray.getJSONObject(i);
JSONArray columnValues = item.getJSONArray("columnValues");
iterator = columnValues.iterator();
while (iterator.hasNext()) {
String key = String.valueOf(iterator.next());//得到键
String value=item.getString(key);//得到值
}
}