0

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

2
  • @Vishwa --its a json response sir i have hit the service through a rest client and i got this response. Its a valid one because it has curly braces and square braces also. Anyways thanks for your response! Commented Aug 18, 2015 at 12:55
  • possible duplicate of how to parse JSONArray in android Commented Aug 24, 2015 at 11:11

1 Answer 1

1

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) );
}
Sign up to request clarification or add additional context in comments.

5 Comments

Awesome! Thanks a lot... Only you have to put textArray.length() instead of textArray.size() and thats it!
Whoops, I was typing from memory. I'll edit that, thanks for warning.
Anyways but poss you rocks :)
Glad it helped. Feel free to accept the answer to get it out of unanswered queue
There is a check under a number to mark the answer as "solved my problem" basically.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.