我正在研究 json 解析。 我正在以 JSON 数组的形式收到响应,在 JSON 数组的旁边是另一个 JSON 数组。 我不会热解析这个。在侧 json 数组中获取 json 数组对象我是 json 的新手,所以请需要帮助。
这是我的回应:-
[
[
{
"Postcode": "BR6 0NH",
"Notes": null,
"Name": "Tesco Pharmacy (Orpington), Bromley, London",
"Phone": "01689 307447",
"Address": "10 AUGUSTUS LANE, ORPINGTON",
"ServiceId": 0,
"Capacity": null,
"URL": null,
"Error": null
},
{
"Postcode": "DA14 5BN",
"Notes": null,
"Name": "Tesco Pharmacy, (Edgington Way), Bromley, London",
"Phone": "0208 258 9447",
"Address": "EDGINGTON WAY, SIDCUP",
"ServiceId": 0,
"Capacity": null,
"URL": null,
"Error": null
}
]
]
最佳答案
试试这个
try {
JSONArray mainArry = new JSONArray(strJsonResponse);
JSONArray contentArray = mainArry.getJSONArray(0);
for (int i =0 ;i<contentArray.length(); i++){
JSONObject item = contentArray.getJSONObject(0);
System.out.println("Postcode : " + item.getString("Postcode"));
System.out.println("Notes : " + item.getString("Notes"));
System.out.println("Phone : " + item.getString("Phone"));
System.out.println("Address : " + item.getString("Address"));
System.out.println("ServiceId : " + item.getString("ServiceId"));
System.out.println("Capacity : " + item.getString("Capacity"));
System.out.println("URL : " + item.getString("URL"));
System.out.println("Error : " + item.getString("Error"));
}
} catch (JSONException e) {
e.printStackTrace();
}
关于android - 如何在 JSON 数组 Android 中解析 JSON 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24772245/