Reputation: 523
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.
Upvotes: 2
Views: 632
Reputation: 5189
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.
Upvotes: 0
Reputation: 1317
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
Upvotes: 0