Java 在Android中提取我的JSON结果
我的JSon数组返回如下Java 在Android中提取我的JSON结果,java,android,json,asynchronous,background,Java,Android,Json,Asynchronous,Background,我的JSon数组返回如下 我想提取它,我知道我可以将它放入JSONObject中进行初始化,但现在使用optJSONArray函数时,我没有要提取的数组名 JSONObject jsonResponse = new JSONObject(result); JSONArray data = jsonResponse.optJSONArray("ArrayNameWhichIsMissing"); 请告诉我如何提取该数组。我认为您可以得到响应,因为JSONArray也是这样 JSONArra
我想提取它,我知道我可以将它放入JSONObject中进行初始化,但现在使用optJSONArray函数时,我没有要提取的数组名
JSONObject jsonResponse = new JSONObject(result);
JSONArray data = jsonResponse.optJSONArray("ArrayNameWhichIsMissing");
请告诉我如何提取该数组。我认为您可以得到响应,因为JSONArray也是这样
JSONArray objj = new JSONArray("your json string");
评论我的结果我想你们可以得到回复,因为JSONArray也是这样的
JSONArray objj = new JSONArray("your json string");
[ // json array node
{ // json object node
"StudentID": "BS231",
"ChildName": "Vishesh Malhotra",
"ClassName": "4th Class",
"Attendance": false
},
{
"StudentID": "BS233",
"ChildName": "Anisha Malhotra",
"ClassName": "6th Class",
"Attendance": false
}
]
评论我的结果
[ // json array node
{ // json object node
"StudentID": "BS231",
"ChildName": "Vishesh Malhotra",
"ClassName": "4th Class",
"Attendance": false
},
{
"StudentID": "BS233",
"ChildName": "Anisha Malhotra",
"ClassName": "6th Class",
"Attendance": false
}
]
您有一个json数组
JSONArray jr = new JSONArray("myjsonstring");
for(int i =0;i<jr.length();i++)
{
JSONObject jb = (JSONObject)jr.get(i);
String id = jb.getString("StudentID");
Log.i(".......",id);
// Similar for other ChildName and ClassName
// use getBoolean for attendance
}
您有一个json数组
JSONArray jr = new JSONArray("myjsonstring");
for(int i =0;i<jr.length();i++)
{
JSONObject jb = (JSONObject)jr.get(i);
String id = jb.getString("StudentID");
Log.i(".......",id);
// Similar for other ChildName and ClassName
// use getBoolean for attendance
}
解析Json的简单方法是使用GSON库将josn对象或数组转换为java类对象。解析Json的简单方法是使用GSON库将josn对象或数组转换为java类对象。如果您不熟悉Json解析,查找名为
Jackson-JSON-Parser
的库。如果您不熟悉JSON解析,请查找名为Jackson-JSON-Parser
的库。是的,Raghunandan是对的,我已经有了JSONArray。我需要的只是直接放入JSONArray并使用它。是的,Raghunandan是对的,我已经有了JSONArray,我所需要的只是直接放入JSONArray并使用它