0
可能重复:
JavaScript “For …in” with Arrays从复杂的JSON对象创建JavaScript数组
我非常新的JSON。我已经在stackoverflow上搜索了一个答案,但有点困惑,所以我不知道我是否偶然发现了一个解决方案。所以,我决定发布我的代码和需求,希望能够申请一个解决方案。
如果已经有一个解决方案存在,我提前道歉,只能想象我只是不明白我在看什么。
我有一个JSON对象,它是这样的:
{
"0": [
{
"uguid": "11111-11111-11111",
"username": "username",
"password": "",
"first_name": "User1",
"last_name": "Name1",
"title": "title here",
"group_guid": "g0001",
"force_pw_reset": "f",
"permissions": [
[
"p1",
"p2",
"p3",
"p4",
"p5"
]
],
"active": "t",
"t_access": [
[]
],
"i_access": [
[]
],
"c_access": [
[]
],
"class_name": "class name",
"method": "method name"
}
],
"1": [
{
"uguid": "22222-22222-2222",
"username": "username2",
"password": "",
"first_name": "User2",
"last_name": "Name2",
"title": "",
"g_guid": "g0002",
"force_pw_reset": "f",
"permissions": [
[
"p1",
"p2",
"p3",
"p4",
"p5",
"p6"
]
],
"active": "t",
"t_access": [
[]
],
"i_access": [
[]
],
"c": [
[
"c0001"
]
],
"class_name": "class name",
"method": "method name"
}
],
"2": [
{
"u_guid": "33333-33333-33333",
"username": "username3",
"password": "",
"first_name": "User3",
"last_name": "Pass3",
"title": "",
"gguid": "g0003",
"force_pw_reset": "f",
"permissions": [
[
"p1",
"p2",
"p3"
]
],
"active": "t",
"t_access": [
[
"t0001"
]
],
"i_access": [
[]
],
"c_access": [
[]
],
"class_name": "class name",
"method": "method name"
}
]
}
我希望能够做的就是遍历这个(或任何)JSON和创建数组。我需要能够递归迭代时/需要时。另外,希望解决方案能够处理传递给函数的任何json对象。
更新:我想我应该提到我想创建一个javascript数组,如果这有什么区别。另外,我正在使用json字符串并使用来自douglas crockford的json_parse()来获取对象。我想采取该对象(显示)并创建JavaScript数组。
我发现这个链接,但不知道它是遍历JSON我有:ackoverflow.com/questions/7707646/loop-through-complex-json-object – whoopah