-4

I am facing some problem to get value from my json response. My Json response is as follows:

{
    "changed": [
        "username",
        "phone",
        "profile_picture",
        "public_ind"
    ],
    "failed": []
}

Please anyone give me some clue so that I can get value from my JSON response.

The Heist
  • 1,444
  • 1
  • 16
  • 32
Anupam Roy
  • 31
  • 1
  • 2

2 Answers2

1

Try this:

JSONObject jsonObject = new JSONObject(response);
JSONArray jsonArrayChanged = jsonObject.getJSONArray("changed");
String failed = jsonObject.getString("failed");
for(int i=0;i<jsonArrayChanged.length();i++){
String str = jsonArrayChanged.getString(i);
} 
The Heist
  • 1,444
  • 1
  • 16
  • 32
1
//first parse your root object from json string
JSONObject rootObject = new JSONObject(Sring_data);

//get the json array object
JSONArray changedFields = rootObject.getJSONArray("changed");

//iterate the array object
for (int i = 0; i < changedFields.size(); i++) {
Log.d("", changedFields.getString(i)); //here you will get each array items
}

// parse other json objects other than json array
String failedObj = rootObject.getString("failed");
Deniz
  • 12,332
  • 10
  • 44
  • 62