Я новичок в android, хотя мне приходится сталкиваться с проблемой при анализе массива json с массивом.разбор массива json с массивом через GSON
{
"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-using-gson-in-android-tutorial/ –
спасибо за помощь, но я попробовал одну из ваших ссылок, но, похоже, она тоже не работает, она дает следующую ошибку: ожидается строка, но BEGIN_ARRAY в строке 1 столбца 10- @SuhasB –