Android - Java - Get nth element in JSONObject -
Android - Java - Get nth element in JSONObject -
my json file contains several attributes. 1 of them list of objects. need access list via numerical key, ie 1st, 2nd etc element.
when getting nth element want access attributes alphabetical key.
example:
myobj.get("itemlist").get(0).get("attribute") if i'm forced convert whole thing jsonarray (afaik) can't access attributes via key position.
here's json string:
{ "id": 1, "items": [ { "id": 1, "type": "video", "name": "test.mp4" }, { "id": 2, "type": "image", "name": "pic.jpg" } ], "name": "test" } any ideas?
ok, don't quite understand why when next works:
jsonarray mylist = new jsonobject(filepath).getjsonarray("items"); system.out.println((((jsonobject) mylist.get(1)).get("type"))); so omitted myobj , targeted list directly.
java android json object
Comments
Post a Comment