2
votes

I have a JSONArray:

myArray => [{"key1" : "value1", "key2" : "value2"}, {"key3" : "value3", "key4" : "value4"}]

If I do myArray.get(1); I get a Object.

I want the single keys and values of myArray[1]. How can I do this? There is a way to have a HashMap that contains {"key3" : "value3", "key4" : "value4"} ?

Please help me, thanks.

2

2 Answers

0
votes

Use getJSONObject(1).getString("key3"); and put the returned value in your HashMap. I am not sure if there is an "automatic" way to do this. You can look at the documentation for more examples.

0
votes

Instead of using myArray.get(), use myArray.getJSONObject() to return a JSONObject. You can call getString(key), getDouble(key), getInt(key), etc on the JSONObject to access the values. See the documentation at http://developer.android.com/reference/org/json/JSONObject.html and http://developer.android.com/reference/org/json/JSONArray.html