【发布时间】:2017-09-30 19:07:21
【问题描述】:
我有一个要解码的嵌套 JSON 数组。我已经找到了一种方法来解码对象中的指定信息,但效果不是很好。
这是我用来从 JSON 对象中解码(名称、封面和街道)的代码:
JSONArray jsonArray = response.getJSONArray("data");
for (int i=0; i < jsonArray.length();i++){
JSONObject events = jsonArray.getJSONObject(i);
String name = events.getString("name");
JSONObject cover = events.getJSONObject("cover");
String imgurl = cover.getString("source");
JSONObject place = events.getJSONObject("place");
JSONObject loc = place.getJSONObject("location");
String street = loc.getString("street");
ItemListView item = new ItemListView(name,street,imgurl);
listItems.add(item);
adapter = new ItemListAdapter(listItems, getActivity());
recyclerView.setAdapter(adapter);
}
我想解码更多信息,例如描述、结束时间和开始时间。
JSON 数据结构如下所示:
{
"data": [
{
"description": "",
"end_time": "",
"name": "",
"place": {
"name": "",
"location": {
"city": "",
"country": "",
"latitude": 0000000,
"longitude": 000000,
"street": ""
},
"id": ""
},
"start_time": "",
"id": ""
},
{
"description": "",
"end_time": "",
"name": "",
"place": {
"name": "",
"location": {
"city": "",
"country": "",
"latitude": 0000000,
"longitude": 000000,
"street": ""
},
"id": ""
},
"start_time": "",
"id": ""
}
]
}
我将解码后的信息放在我的 Android 应用程序的 ListView 中,这就是为什么我在代码中有一个适配器和 ListView。
非常感谢任何帮助:) 提前致谢。
【问题讨论】:
标签: android arrays json nested decode