首先参考http://blog.csdn.net/lishuangzhe7047/article/details/28880009
写的实在是好
public static void main(String[] args) throws JSONException {
String s="[{name1:{name2:{name3:'value1',name4:'value2'}}},{name5:value3}]";
JSONArray jsonArray=new JSONArray(s);
JSONObject js1= (JSONObject) jsonArray.get(0);
JSONObject js2= (JSONObject) jsonArray.get(1);
JSONObject js3=js1.getJSONObject("name1");
JSONObject js4=js3.getJSONObject("name2");
String js5=(String) js4.get("name4");
System.out.println(js1);
System.out.println(js2);
System.out.println(js3);
System.out.println(js4);
System.out.println(js5);
}
输出:
{"name1":{"name2":{"name4":"value2","name3":"value1"}}} {"name5":"value3"} {"name2":{"name4":"value2","name3":"value1"}} {"name4":"value2","name3":"value1"} value2
原文链接:/json/289073.html