我如何从这个 json 访问多级 json 值?fr eg:in 这个 json 从 dish_description 访问菜单
How do i acess multilevel json value from this json ?fr eg:in this json access menu from dish_description
[
{
"vendor_name": "Chef Neha Jain",
"vendor_avatar": "http://www.avatarsdb.com/avatars/dear_god.jpg",
"vendor_type": "indivisual",
"vendor_rating": "0",
"vendor_phone": "9875463210",
"vendor_address": "Golf Course Road Sector 54 New Vatika Towers Gurgaon",
"vendor_neighbourhood": "Sector 54",
"vendor_city": "gurgaon",
"dish_id": "2",
"dish_name": "Dal Baati Churma Thali",
"dish_image": "http://s3-ap-southeast-1.amazonaws.com/elasticbeanstalk-ap-southeast-1-779583297639/Dish%2FImages%2FDal+Baati+Churma+Thali%2FNormal%2Fdal_baati_churma_thali-hdpi.jpg",
"dish_description": "{\"main\":\"Dine in on a grand feast of authentic cuisine from Rajasthan. Panchmel Dal, Baati, Churma, Tadka Kadhi, Lehsun Chutney, Jeera Rice all come together to create a culinary memory that you would have seldom experience before.\",\"other\":\"Served as Panchmel Dal, 2 Baatis, Churma, Tadka Kadhi, Lehsun Chutney and Jeera Rice\"}",
"dish_palate": "[\"2\",\"4\"]",
"dish_tags": "Baati,Daal",
"dish_cost": "200",
"dish_price": "250",
"dish_rating": "4.5",
"$$hashKey": "object:7"
}
]
参考下面的方法来解析 json 响应,如果你在字符串中得到响应,否则删除 JSONArray array = new JSONArray("res") line if getting json array.
try {
JSONArray array = new JSONArray("res");
for (int i = 0; i < array.length(); i++) {
JSONObject jsonObject = array.getJSONObject(i);
String vendor_name = jsonObject.getString("vendor_name");// same way parse all string
if(jsonObject.has("dish_description")){
String dish = jsonObject.getString("dish_description");
dish = dish.replaceAll("[\W]", "");
JSONObject jsonObject2 = new JSONObject(dish);
String main = jsonObject2.getString("main");// same way get other one
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
[
{
"vendor_name": "Chef Neha Jain",
"vendor_avatar": "http://www.avatarsdb.com/avatars/dear_god.jpg",
"vendor_type": "indivisual",
"vendor_rating": "0",
"vendor_phone": "9875463210",
"vendor_address": "Golf Course Road Sector 54 New Vatika Towers Gurgaon",
"vendor_neighbourhood": "Sector 54",
"vendor_city": "gurgaon",
"dish_id": "2",
"dish_name": "Dal Baati Churma Thali",
"dish_image": "http://s3-ap-southeast-1.amazonaws.com/elasticbeanstalk-ap-southeast-1-779583297639/Dish%2FImages%2FDal+Baati+Churma+Thali%2FNormal%2Fdal_baati_churma_thali-hdpi.jpg",
"dish_description": "{\"main\":\"Dine in on a grand feast of authentic cuisine from Rajasthan. Panchmel Dal, Baati, Churma, Tadka Kadhi, Lehsun Chutney, Jeera Rice all come together to create a culinary memory that you would have seldom experience before.\",\"other\":\"Served as Panchmel Dal, 2 Baatis, Churma, Tadka Kadhi, Lehsun Chutney and Jeera Rice\"}",
"dish_palate": "[\"2\",\"4\"]",
"dish_tags": "Baati,Daal",
"dish_cost": "200",
"dish_price": "250",
"dish_rating": "4.5",
"$$hashKey": "object:7"
}
]
参考下面的方法来解析 json 响应,如果你在字符串中得到响应,否则删除 JSONArray array = new JSONArray("res") line if getting json array.
try {
JSONArray array = new JSONArray("res");
for (int i = 0; i < array.length(); i++) {
JSONObject jsonObject = array.getJSONObject(i);
String vendor_name = jsonObject.getString("vendor_name");// same way parse all string
if(jsonObject.has("dish_description")){
String dish = jsonObject.getString("dish_description");
dish = dish.replaceAll("[\W]", "");
JSONObject jsonObject2 = new JSONObject(dish);
String main = jsonObject2.getString("main");// same way get other one
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}