Mano Mano - 1 year ago 52
Android Question

How to get particular value from JSON response in Android?

I want to get the value of

from the below JSON response and store it locally.Here's the code:

private class GetContacts extends AsyncTask<Void, Void, Void> {

protected Void doInBackground(Void... arg0) {
// Creating service handler class instance
ServiceHandler sh = new ServiceHandler();

// Making a request to url and getting response
String jsonStr = sh.makeServiceCall(url, ServiceHandler.GET);

if (jsonStr != null) {
try {
JSONObject jsonObj = new JSONObject(jsonStr);

//JSONArray contacts;
contacts = jsonObj.getJSONArray("response");
Log.d("Response: ", "> " + contacts);

} catch (JSONException e) {
} else {
Log.e("ServiceHandler", "Couldn't get any data from the url");
return null;

My Response :






Answer Source

You need to create a JSON Object from json String, you get and then retrieve its data:

JSONObject json= new JSONObject(responseString);  //your response
try {
    String result = json.getString("result");    //result is key for which you need to retrieve data
    } catch (JSONException e) {
        // TODO Auto-generated catch block

Hope it helps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download