我有以下 JSON 对象:
[
{
"comments": [
{
"created_at": "2011-02-09T14:42:42-08:00",
"thumb": "xxxxxxx",
"level": 1,
"id": 214,
"user_id": 41,
"parent_id": 213,
"content": "<p>xxxxxx</p>",
"full_name": "xx K"
},
{
"created_at": "2011-02-09T14:41:23-08:00",
"thumb": "xxxxxxxxxxxxx",
"level": 0,
"id": 213,
"user_id": 19,
"parent_id": null,
"content": "<p>this is another test</p>",
"full_name": "asd asd asd asd asd"
}
],
"eee1": "asdadsdas",
"eee2": "bbbbb"
}
]
这是来自 $.ajax
请求,我已经成功......
success: function (dataJS) {
console.log(dataJS);
console.log(dataJS[eee1]);
console.log(dataJS.comments);
}
问题是我无法访问 JSON 对象中的项目,即使 dataJS 确实在控制台中正确显示。想法?
最佳答案
那是因为你的基础对象也是一个数组。
console.log(dataJS[0].comments[0]);
我想这行得通
关于javascript - 如何访问 JSON 对象中的数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5173603/