遍歷jsonArray和jsonObject

遍歷jsonArrayjson

String str = "[{name:'a',value:'aa'},{name:'b',value:'bb'},{name:'c',value:'cc'}]" ; 
JSONArray json = JSONArray.fromObject(str ); 
if(json.size()>0){ for(int i=0;i<json.size();i++){ JSONObject job = json.getJSONObject(i);  
    System.out.println(job.get("name")+"=") ;  
 } }

遍歷jsonObjectspa

JSONObject jsonObject = new JSONObject(jsonString); Iterator iterator = jsonObject.keys(); while(iterator.hasNext()){ key = (String) iterator.next(); value = jsonObject.getString(key); }
相關文章
相關標籤/搜索