Swapnil Lanjewar
Swapnil Lanjewar

Reputation: 686

How to parse a json array within a json object in android

Following is the JSON response i have got from a web service. I want to parse it in an android app:

{"text":["Gayatri Hari Mankar","Prajaval V. Kakade","ram  joshi","Revati R Sharma","Sneha M Verma","Sumeet N Wankar"],"status":1000}

I want to retrieve all the names under the text array.

Its a different case than that of the one mentioned below. how to parse JSONArray in android

Upvotes: 0

Views: 535

Answers (1)

poss
poss

Reputation: 1789

It's just simple parsing of array with variable length.

JSONObject wholeObject = new JSONObject(); //add your response here, from string for example
JSONArray textArray = wholeObject.getJSONArray("text");
for (int i = 0; i < textArray.length(); i++) {
    Log.d("text", textArray.getString(i) );
}

Upvotes: 1

Related Questions