-2
   [
  {
    "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"
  }
]
Andrey Korneyev
  • 26,353
  • 15
  • 70
  • 71
  • Man you should at least search? If you are new to android development then learn [JSON Parsing](http://www.technotalkative.com/android-json-parsing/) – Paresh Mayani May 22 '15 at 10:36
  • And there are many questions/answers already exists on Stackoverflow! – Paresh Mayani May 22 '15 at 10:37
  • Yes i did search,but i am confused on accessing the main tag inside dish description since the parenthesis is inside the quotes.Can anybody help me here? – Sourav Mandal May 22 '15 at 10:42
  • If you don't want to manually parse and if your JSON is fixed then use `GSON` library! With that you just need to define the POJO class! – Paresh Mayani May 22 '15 at 10:46

1 Answers1

1

Refer below way to parse json response, If you are getting response in string otherwise remove 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();
                }
Anjali Tripathi
  • 1,477
  • 9
  • 28