Arrays 如何在java代码中使用jsonArray读取json响应
我有一个查询,我必须从下面提到的json响应中读取键“studentData”下的键“class”。 { “学生数据”:[ { “姓名”:“约翰”, "阶级":二,, “rollno”:“2015年” } ], “登记年份”:2017年 } 请帮忙 提前谢谢Arrays 如何在java代码中使用jsonArray读取json响应,arrays,json,httpclient,Arrays,Json,Httpclient,我有一个查询,我必须从下面提到的json响应中读取键“studentData”下的键“class”。 { “学生数据”:[ { “姓名”:“约翰”, "阶级":二,, “rollno”:“2015年” } ], “登记年份”:2017年 } 请帮忙 提前谢谢 JSONObject jsonObjectResponse = new JSONObject(response.toString()); //obtain the object JSONArray jsonMainNode = jsonOb
JSONObject jsonObjectResponse = new JSONObject(response.toString()); //obtain the object
JSONArray jsonMainNode = jsonObjectResponse.optJSONArray("studentData");//get array from object
JSONObject jsonChildNode = jsonMainNode.getJSONObject(0);//get first object in array
String studentDataValue = jsonChildNode.optString("class");//obtain value from class key