配列内のjson配列を解析する際に問題に直面していますが、私は新しいアンドロイドです。GSONを使って配列内のjson配列を解析する
{
"menu": [
{
"Soups": [
{
"name": "Safed Tamatar aur Tulsi ",
"price": 150,
"description": "",
"veg": true,
"spicy": null
},
{
"name": "Dum Murg",
"price": 168,
"description": "",
"veg": false,
"spicy": null
},
{
"name": "Murg Zaffrani",
"price": 168,
"description": "",
"veg": false,
"spicy": null
},
{
"name": "Tomato Dhania",
"price": 150,
"description": "",
"veg": true,
"spicy": null
}
]
},
{
"Starters": [
{
"name": "Achari Paneer tikka",
"price": 347,
"description": "",
"veg": true,
"spicy": null
},
{
"name": "Paneer Tikka",
"price": 347,
"description": "",
"veg": true,
"spicy": null
},
{
"name": "Murg Tikka",
"price": 393,
"description": "",
"veg": false,
"spicy": null
},
{
"name": "Tandoori Murg (Half)",
"price": 410,
"description": "",
"veg": false,
"spicy": null
},
{
"name": "Tandoori Murg (Full)",
"price": 851,
"description": "",
"veg": false,
"spicy": null
},
{
"name": "Macchi Tikka",
"price": 626,
"description": "",
"veg": false,
"spicy": null
}
]
},
{
"Main Course": [
{
"name": "Jeera Aloo",
"price": 275,
"description": "",
"veg": true,
"spicy": null
},
{
"name": "Paneer Tikka Masala",
"price": 392,
"description": "",
"veg": true,
"spicy": null
},
{
"name": "Palak Paneer",
"price": 370,
"description": "",
"veg": true,
"spicy": null
},
{
"name": "Murg Kadhai",
"price": 428,
"description": "",
"veg": false,
"spicy": null
},
{
"name": "Murg Tikka Masala",
"price": 428,
"description": "",
"veg": false,
"spicy": null
},
{
"name": "Palak Gosht",
"price": 455,
"description": "",
"veg": false,
"spicy": null
},
{
"name": "Macchi Kadhai",
"price": 545,
"description": "",
"veg": false,
"spicy": null
}
]
},
{
"Rice": []
},
{
"Breads": []
},
{
"Accompaniments": []
},
{
"Beverages": []
},
{
"Dessert": []
},
{
"Signature Mocktails": []
},
{
"Wraps": []
},
{
"Lentils": [
{
"name": "Dal Tadka",
"price": 226,
"description": "",
"veg": true,
"spicy": null
},
{
"name": "Dal Kolhapuri",
"price": 226,
"description": "",
"veg": true,
"spicy": null
},
{
"name": "Dal Makhani",
"price": 275,
"description": "",
"veg": true,
"spicy": null
}
]
}
],
"name": "Zaffran"
}
このファイルを解析したいのですが、インターネット上にこのファイルをGSONで解析するコードはありません。 私は次のコードを使用:
JSONObject jsonObject = (JSONObject) new JSONTokener(response).nextValue();
JSONArray jsonArray = jsonObject.getJSONArray("menu");
String jsonString = jsonArray.toString();
Type type = new TypeToken<Map<String, String>>() {
}.getType();
Map<String, String> myMap = new Gson().fromJson(jsonString, type);
for (Map.Entry<String, String> entry : myMap.entrySet()) {
key = entry.getKey();
value = entry.getValue();
// do stuff
}
responseView.setText(value);
をしかし、それは文字列が見つかった配列を期待エラーが発生します。助けてください
これはyou.httpsを助ける://www.javacodegeeks.com/2011/01/android-json-parsing-gson-tutorial.html&http://blog.nkdroidsolutions.com/how-to -parsing-json-array-gson-in-android-tutorial/ –
助けてくれてありがとうございますが、あなたのリンクの1つを試しましたが、どちらもうまくいかないようですが、次のエラーが表示されます:BEGIN_ARRAY行1の列10- @SuhasB –