【发布时间】:2015-04-28 11:22:25
【问题描述】:
这就是 JSON 的样子:
[{
"pmid": "2",
"name": " MANAGEMENT",
"result": "1",
"properties": [
{
"prop_id": "32",
"prop_name": "Bonneville",
"address": "122 Lakeshore",
"city": "Ripley",
"state": "OH",
"zip": "11454",
"lat": "41.123",
"long": "-85.5034"
}
]
}]
我正在尝试在 Android 中使用以下 Java 代码对其进行解析:
JSONObject jObj = null; 尝试 { jObj = new JSONObject(jsonStr);
// We get weather info (This is an array)
JSONArray jArr = jObj.getJSONArray("properties");
// We use only the first value
//JSONObject JSONWeather = jArr.getJSONObject(0);
JSONObject c = jArr.getJSONObject(0);
String name = c.getString(TAG_NAME);
String email = c.getString(TAG_EMAIL);
String phone = c.getString(TAG_PHONE);
} catch (JSONException e) {
e.printStackTrace();
}
return null;
虽然我没有得到任何结果。如何成功解析这个 JSON?我正在使用 Android Studio。
另外,如果数组中有多个部分,我们如何确保每个部分都被打印出来?
【问题讨论】: