有没有什么方法可以在 JSON 中嵌套对象,这样我就不必用所有东西制作数组?为了正确解析我的对象,我似乎需要这样的结构:
{"data":[{"stuff":[
{"onetype":[
{"id":1,"name":"John Doe"},
{"id":2,"name":"Don Joeh"}
]},
{"othertype":[
{"id":2,"company":"ACME"}
]}]
},{"otherstuff":[
{"thing":
[[1,42],[2,2]]
}]
}]}
如果我将此对象获取到名为“result”的变量中,我必须像这样访问嵌套对象:
result.data[0].stuff[0].onetype[0]
and
result.data[1].otherstuff[0].thing[0]
这对我来说似乎笨拙且多余,如果可能的话我更喜欢:
result.stuff.onetype[0]
and
result.otherstuff.thing
但是当一切都是数组时,如何直接使用对象键呢?对于我困惑且未受过教育的头脑来说,这样的事情似乎更合适:
{"data":
{"stuff":
{"onetype":[
{"id":1,"name": ""},
{"id":2,"name": ""}
]}
{"othertype":[
{"id":2,"xyz": [-2,0,2],"n":"Crab Nebula","t":0,"c":0,"d":5}
]}
}
{"otherstuff":
{"thing":
[[1,42],[2,2]]
}
}
}
我可能在这里误解了一些基本的东西,但我无法让 jQuery 解析器(也无法让 jQuery 1.4 使用的本机 FF 解析器)接受第二个样式对象。如果有人能启发我,我将不胜感激!