How do I parse json key value pairs inside a json object using Volley Android

Viewed 154

How do I parse this using Volley

{
    "ref": "suc",
    "contactInfo": {
        "name": "Jezzi",
        "age": "3",
        "Place": "Kochi"
    }
}

Code in Android

@Override
public void onResponse(String response) {

   try {
     JSONObject jsonObject = new JSONObject(response);
     String ref = jsonObject.getString("ref");
    
   } catch (Exception e ) {

       Log.i("Hello", e.toString);
   }
}

I'm getting string value ref, but I don't know how to get the other values.

1 Answers

I think this might help you:

try {
     JSONObject jsonObject = new JSONObject(response);
     String ref = jsonObject.getString("ref");
     JSONObject contactJsonObject = jsonObject.getJSONObject("contactInfo");
     String name = contactJsonObject.getString("name");
     // and other values like this
   } catch (Exception e ) {

       Log.i("Hello", e.toString);
   }
Related