-2

I'm getting the JSON response as {"Sync-string" [{"Sync-check[{"Response":"N"}]}]}.

Right now I want to check the response is "Y" or "N".How can I check the response is n or y .Can someone help me here.Any help is appreciable.

Aditi Parikh
  • 1,522
  • 3
  • 13
  • 34
JAndroid
  • 29
  • 1
  • 1
  • 5

1 Answers1

0

Go through this tutorial to know about json structure and how can parse json in Android App. Check with this link and if you any query post it!

Update

First know the structure of the json. Json node starts with "[" represents the array and "{" represents Json Object. In your response,

 {"Sync-string" : [{"Sync-check[{"Response":"N"}]}]}

Get the Json Object named "Sync-string" like,

JSONObject jsonObj = new JSONObject("ur json string");
JSONArray contacts = jsonObj.getJSONArray("Sync-string");//getting the array

Now loop through your JSON Array like,

for (int i = 0; i < contacts.length(); i++) {
                    JSONObject c = contacts.getJSONObject(i);//get first object in array
                     JSONArray innerarray = jsonObj.getJSONArray("Sync-check");//sync-check array
  for (int i = 0; i < innerarray.length(); i++) {
  JSONObject c = innerarray.getJSONObject(i);
                    String id = c.getString("Response");
}
}

Try this, but not verified code

micky
  • 508
  • 5
  • 17
  • Suppose here is my new json string = {"Sync-string" [{"Sync-check[{"Response":"y"} , "dgrer","ertetye3"]}]} then how to parse it – JAndroid Apr 24 '15 at 11:54
  • First let us know what u hav tried so far? Then only we can help you...Seems you not yet tried anything – micky Apr 24 '15 at 11:56
  • I'm trying to check if {"Sync-string" [{"Sync-check[{"Response":"y"} , "dgrer","ertetye3"]}]} then data is there and save into local db .If {"Sync-string" [{"Sync-check[{"Response":"N"}]}]} then alert msg – JAndroid Apr 24 '15 at 11:58