【发布时间】:2017-03-20 10:23:11
【问题描述】:
我是android的新手。所以请不要对这个问题投反对票。 我有一个应用程序,我必须将数据从嵌套的 json 提取到一个列表视图中。
这是我的 json 代码:
{
"status": 1,
"data": [
{
"iMainServiceId": 1,
"main": "NAILS",
"sub": [
{
"iSubServiceId": 1,
"vName": "Manicure",
"fPrice": 15,
"vDuration": "20 Minutes"
},......
]
}
]
}
如json.. 我想在一个列表视图中区分两个数组作为标题和内容..
例如, 我必须在列表视图内容中显示 json 数据,例如
header value=Nails
raw value:iSubServiceId": 1,
"vName": "Manicure",
"fPrice": 15,
"vDuration": "20 Minutes"
我做的是:
JSONObject json = new JSONObject(result);
String status = json.getString("status");
Log.d("Status:", status);
String data = json.getString("data");
Log.d("Data:", data);
MainList = new ArrayList<MainArray_method>();
JSONArray MainArray = json.getJSONArray("data");
for (int i = 0; i < MainArray.length(); i++) {
JSONObject jsonObject = MainArray.getJSONObject(i);
MainList.add(new MainArray_method(MainArray.getJSONObject(i).getString("iMainServiceId"),
MainArray.getJSONObject(i).getString("main")));
SubList = new ArrayList<SubArray_method>();
JSONArray SubArray = jsonObject.getJSONArray("sub");
for (int j = 0; j < SubArray.length(); j++) {
SubList.add(new SubArray_method(SubArray.getJSONObject(j).getString("iSubServiceId"),
SubArray.getJSONObject(j).getString("vName"),
SubArray.getJSONObject(j).getString("fPrice"),
SubArray.getJSONObject(j).getString("vDuration")));
}
}
main_adapter = new MainArray_adapter(getApplicationContext(), MainList);
notification_header.setAdapter(main_adapter);
sub_adapter = new SubArray_adapter(getApplicationContext(), SubList);
notification_raw.setAdapter(sub_adapter);
} catch (JSONException e) {
e.printStackTrace();
}
}
我该怎么办请告诉我。 提前致谢。
【问题讨论】:
-
搜索json解析教程
-
我已经完成了 json 解析..但不知道如何在 listview 中获取它..
-
你在哪里解析和存储你的 JSON 数据??
-
显示你做了什么。否则怎么会有人现在你想要什么