{
"List":[
{"age":20,"name":"0号"},
{"age":21,"name":"1号"},
{"age":22,"name":"2号"},
{"age":23,"name":"3号"}
],
"Data": {"address":"China","sex":"1","name":"jack","age":23}
}
=========================================================
JSONObject fromObject = JSONObject.fromObject(jsonStr);
//解析Object
JSONObject object = fromObject.getJSONObject("Data");
String string = object.getString("name");
int age = object.getInt("age");
String address = object.getString("address");
String sex = object.getString("sex");
//解析List
JSONArray jsonArray = fromObject.getJSONArray("List");
for(int i=0;i<jsonArray.size();i++){
JSONObject obj = jsonArray.getJSONObject(i);
String name = obj.getString("name");
int ageN = obj.getInt("age");
System.out.println(name+ageN);
}
###################################################################
###################################################################
List的JSON
[
{"age":20,"name":"0号"},
{"age":21,"name":"1号"},
{"age":22,"name":"2号"},
{"age":23,"name":"3号"}
]
//解析List
JSONArray jsonArray2 = JSONArray.fromObject(jsonStr);
for(int i=0;i<jsonArray2.size();i++){
JSONObject obj = jsonArray2.getJSONObject(i);
String name = obj.getString("name");
int ageN = obj.getInt("age");
System.out.println(name+ageN);
}