My json resposnse from webservice is like
{"d":"[{\"userid\":507}]"}
in Android. I need to get the userid from this response. How is it possible?
Asked
Active
Viewed 97 times
1

Deepu T
- 724
- 7
- 20
-
possible duplicate of [How to parse JSON in Java](http://stackoverflow.com/questions/2591098/how-to-parse-json-in-java) – Jules G.M. Sep 10 '13 at 10:05
-
Please look at the example . [Anroid JSON Parsing Tutorial](http://www.androidhive.info/2012/01/android-json-parsing-tutorial/) – Ye Lin Aung Sep 10 '13 at 10:09
-
I didn't get the exact answer for my solution. That's why i posted this question – Deepu T Sep 10 '13 at 11:01
2 Answers
2
try this way
private void parseJson(String response) {
try{
JSONObject main = new JSONObject(response);
JSONArray d = main.getJSONArray("d");
for (int i = 0; i <d.length(); i++) {
JSONObject item = d.getJSONObject(i);
System.out.println("userid : " + item.getString("userid"));
}
}catch (Exception e) {
}
}

Biraj Zalavadia
- 28,348
- 10
- 61
- 77
1
At last i got the exact answer for my solution . I got the userid from my response using this code`
result=(String) jobj.getString("d");
JSONArray arr = new JSONArray(result);
JSONObject js=arr.getJSONObject(0);
String userid=js.getString("Userid");`

Deepu T
- 724
- 7
- 20