java如何通过json读取嵌套的json对象
"strs": [
{
"strs11": 111,
"strs12": 122,
"strs13": 133
{
"strs21": 211,
"strs22": 222,
"strs23": 233
}
],
"str2": 22,
"str3": 33,
"str4":44
URL url = new URL("http://localhost/test.jspx");
URLConnection urlconn = url.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(urlconn.getInputStream(),"utf-8"));
String repStr = null;
if ((repStr = reader.readLine()) != null) {
JSONObject jObj = JSONObject.fromObject(repStr);
JSONArray jary=jObj.getJSONArray("strs");
for (int i=0;i<jary.size();i++) {
JSONObject obj = jary.getJSONObject(i);
String s2=obj.getString("strs11");
}
对象数据内容如下:
{
"str1": 11,"strs": [
{
"strs11": 111,
"strs12": 122,
"strs13": 133
{
"strs21": 211,
"strs22": 222,
"strs23": 233
}
],
"str2": 22,
"str3": 33,
"str4":44
}
URL url = new URL("http://localhost/test.jspx");
URLConnection urlconn = url.openConnection();
BufferedReader reader = new BufferedReader(new InputStreamReader(urlconn.getInputStream(),"utf-8"));
String repStr = null;
if ((repStr = reader.readLine()) != null) {
JSONObject jObj = JSONObject.fromObject(repStr);
JSONArray jary=jObj.getJSONArray("strs");
for (int i=0;i<jary.size();i++) {
JSONObject obj = jary.getJSONObject(i);
String s2=obj.getString("strs11");
}
}