0

I have a JSONArray like below

System.out.println(jsonArray.get(i));
//output
["4","3","2","1","3","5","6"]

How can i access the values inside the array. For Example if i want value 2 from the above array which is at index 2, what should i use to get the value

4
  • jsonArray.get(2) does not work? Commented May 31, 2015 at 3:51
  • Does jsonArray.get(i).getInt(2) work? It looks like you have a multidimensional array. Commented May 31, 2015 at 3:51
  • Yes.. I have a 2-dimensional array.jsonArray.get(i).getInt(2) is not working..The method getInt(int) is undefined for the type Object Commented May 31, 2015 at 4:28
  • That's because if you just call get, it returns a java object. To return a JSONObject, you have to look for the methods that have JSON in their name, like getJSONArray - which is what you need Commented May 31, 2015 at 5:54

1 Answer 1

1

Assuming you have a org.json.JSONArray

String s = jsonArray.getJSONArray(i).getString(2);

should do the trick.

Sign up to request clarification or add additional context in comments.

Comments

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.