开发者

JSON and ANDROID

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 开发者_如何学Gothat contains {"key3" : "value3", "key4" : "value4"} ?

Please help me, thanks.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜