我有像这样的json解析
姓名
品牌
值推荐
MPN
我可以在列表视图中显示此值(品牌和mpn)。我想如果我点击品牌它会在列表中显示值推荐值(值a和b)。如果我点击mpn,它也会在列表中显示名称2的值recom(值a和b)。谁能给我建议?谢谢
这是我的json解析
array (
'features' =>
array (
'Recommendations' =>
array (
'id' =>
'NameRecommendation' =>
array (
0 =>
array (
'Name' => 'Brand',
),
'ValueRecommendation' =>
array (
0 =>
array (
'Value' => 'Unbranded/Generic',
),
1 =>
array (
'Value' => 'Canon',
),
2 =>
array (
'Value' => 'Nikon',
),
),
1 =>
array (
'Name' => 'MPN',
),
'ValueRecommendation' =>
array (
0 =>
array (
'Value' => 'mpn1',
),
1 =>
array (
'Value' => 'aas',
),
2 =>
array (
'Value' => 'aab',
),
答案 0 :(得分:0)
检查url
并使用jsonobject
-name
答案 1 :(得分:0)
您可以在JSONArray对象
中阅读此内容以下是示例
JSONArray jsonArr = new JSONArray(jsonStr); // this is you string as formatted in json array if not parse by this construct it will throw the jsonparseexception
现在通过迭代器
遍历这个json的每个对象for(int i=0;i<jsonArr.length();i++){
JSONObject jsonObj = jsonArr.get(i).getJsonObject("value recom");
String a = jsonObj.getString("a"); // here is your data for a object
String b = jsonObj.getString("b"); // here is your data for b object
}
答案 2 :(得分:0)
使用google gson。
var getRowData =
[{
"dayOfWeek": "Sun",
"date": "11-Mar-2012",
"los": "1",
"specialEvent": "",
"lrv": "0"
},
{
"dayOfWeek": "Mon",
"date": "",
"los": "2",
"specialEvent": "",
"lrv": "0.16"
}];
JsonElement root = new JsonParser().parse(request.getParameter("getRowData"));
JsonArray jsonArray = root.getAsJsonArray();
JsonObject jsonObject1 = jsonArray.get(0).getAsJsonObject();
String dayOfWeek = jsonObject1.get("dayOfWeek").toString();
//使用杰克逊时
JsonFactory f = new JsonFactory();
ObjectMapper mapper = new ObjectMapper();
JsonParser jp = f.createJsonParser(getRowData);
// advance stream to START_ARRAY first:
jp.nextToken();
// and then each time, advance to opening START_OBJECT
while (jp.nextToken() == JsonToken.START_OBJECT) {
Map<String,Object> userData = mapper.readValue(jp, Map.class);
userData.get("dayOfWeek");
// process
// after binding, stream points to closing END_OBJECT
}