未能创建JSON
我试图创建一个包含一个主数组的JSON,然后在该数组上它包含三个不同的数组,在这些数组中它包含不同的对象,问题是我创建的逻辑看起来很糟糕未能创建JSON,json,Json,我试图创建一个包含一个主数组的JSON,然后在该数组上它包含三个不同的数组,在这些数组中它包含不同的对象,问题是我创建的逻辑看起来很糟糕 { "FirstArray": [ { "FirstItemThatIsAnArrayToo": [ { "FirstItemOnThisArray": [ {
{
"FirstArray": [
{
"FirstItemThatIsAnArrayToo": [
{
"FirstItemOnThisArray": [
{
"name": "xxx",
"search": "xxx"
}
]
}
],
"SecondItemOnTheFirstArray": [
{
"FirstItemOnThisArray": [
{
"name": "xxx",
"search": "xxx"
}
]
}
],
"ThirthItemOnTheFirstArray": [
{
"FirstItemOnThisArray": [
{
"name": "xxx",
"search": "xxx"
}
]
}
]
}
]
}
我想要的是FirstArray包含三个不同的数组,这些数组我没有放在JSON上,因为它说类型错误,但我想放一个id和一个名称,然后在FirstItemThatIsAnArrayToo内的项中添加更多
希望你能理解这个问题,否则尽管问我
编辑
这应该是JSON示例
这就是我认为可以做到的,也许我用错误的方式处理了这个问题……对于您提供给我们的数据:
{
"listname": "Cars",
"list": [
{
"id": "1",
"name": "Audi",
"list": [
{
"id": "A",
"name": "Audi R8",
"bar": "foo"
},
{
"id": "B",
"name": "Audi R3",
"bar": "foo"
}
]
},
{
"id": "2",
"name": "Golf",
"list": [
{
"id": "A",
"name": "Golf R8",
"bar": "foo"
},
{
"id": "B",
"name": "Golf R3",
"bar": "foo"
}
]
},
{
"id": "3",
"name": "Pew",
"list": [
{
"id": "A",
"name": "Pew R8",
"bar": "foo"
},
{
"id": "B",
"name": "Pew R3",
"bar": "foo"
}
]
}
]
}
我知道你在找什么?@AmitKumarGhosh什么?想把id和名字放在你想要的地方吗?@AmitKumarGhosh放在第一个数组的每个项目上你可以编辑并显示你想要的输出吗?要尝试用Java解析它,让我们看看是否容易:指向第一个列表的名字是什么?我想知道名单上所有人的名字items@Skizo如果设置var json=该json对象,则可以通过json.list访问所有汽车品牌的第一个列表。然后,如果您想访问Audi的列表,可以使用json.list[0].list.Ya,但我有一个方法读取json并将其全部放在一个字符串中,那么如何获取第一个列表我可以这样做:JSONObject obj=new JSONObject str;JSONArray arr=obj.getJSONArraylist;对于int i=0;i
{
"listname": "Cars",
"list": [
{
"id": "1",
"name": "Audi",
"list": [
{
"id": "A",
"name": "Audi R8",
"bar": "foo"
},
{
"id": "B",
"name": "Audi R3",
"bar": "foo"
}
]
},
{
"id": "2",
"name": "Golf",
"list": [
{
"id": "A",
"name": "Golf R8",
"bar": "foo"
},
{
"id": "B",
"name": "Golf R3",
"bar": "foo"
}
]
},
{
"id": "3",
"name": "Pew",
"list": [
{
"id": "A",
"name": "Pew R8",
"bar": "foo"
},
{
"id": "B",
"name": "Pew R3",
"bar": "foo"
}
]
}
]
}