我的 JSON 文件包含几个属性。其中之一是对象列表。我需要通过数字键访问此列表,即第一个、第二个等元素。
当nth element
我想通过字母键访问它的属性时。
例子:
MyObj.get("itemlist").get(0).get("attribute")
如果我这样做,我将被迫将整个事物转换为一个JSONArray
(afaik)我无法通过键访问我的属性而只能通过位置访问我的属性。
这是我的 JSON 字符串:
{
"id": 1,
"items": [
{
"id": 1,
"type": "video",
"name": "test.mp4"
},
{
"id": 2,
"type": "image",
"name": "pic.jpg"
}
],
"name": "test"
}
有任何想法吗?