Reputation: 2351
I have the json like this..
{"source":[{"id":"22","name":"xyz"},{"id":"23","name":"ghj"},
{"id":"24","name":"tuv"}]}
I've to get the value of "id" and "name". How to do that..
I've tried a lot. But can't get the best solution how to do this.
thanks for the help
Upvotes: 1
Views: 107
Reputation: 3476
You want to use following code....
JSONObject jObject = new JSONObject(responseBody);
sourceArray = jObject.getJSONArray("source");
for (int i = 0; i < 3; i++) {
name[i] = sourceArray.getJSONObject(i).getString("name").toString();
id[i] = sourceArray.getJSONObject(i).getInt("id");
}
responseBody is your actual JSON String. Reply if you have any doubts.
Upvotes: 1