我已经尝试了 100 种不同的方法,并花了几天时间浏览 Google 和 Stackoverflow,但我找不到解决这个问题的方法。我在这个 API 响应的主体之后调用的所有内容都返回undefined!
Facebook SDK 的响应如下所示:
[
{
"body": "[
"data": [
{
"name": "Larry Syid Wright",
"administrator": false,
"id": "xxx"
}, {
"name": "Melissa Long Jackson",
"administrator": false,
"id": "xxx"
}, {
"name": "Charlotte Masson",
"administrator": false,
"id": "xxx"
}
],
"paging": {
"next": "url"
}
]"
},{
"body": "{
"data": [
{
"id": "xxx_xxx",
"message": "In honor of Halloween, how many of you have your own ghost stories? Who believes in ghosts and who doesn't?",
"type": "status",
"created_time": "2014-10-31T20:02:01+0000",
"updated_time": "2014-11-01T02:52:51+0000",
"likes": {
"data": [
{
"id": "xxx",
"name": "Joe HerBatman Owenby Jr."
}
],
}
"paging": {
"cursors":
{
"after": "xxx",
"before": "xxx"
}
}
}
},{
"id": "xxx_xxx",
"from": {
"id": "xxx",
"name": "Jessica Starling"
},
"message": "Watching the "Campaign" and I can't help but notice what a fantastic job they did (Will ferrell and all) with that North Carolina accent! Ya'll know we sound different than other southern states ;)",
"type": "status",
"created_time": "2014-11-01T02:36:21+0000",
"updated_time": "2014-11-01T02:36:21+0000",
"likes": {
"data": [
{
"id": "xxx",
"name": "Scott Williams"n
}
]
}
}
],
"paging": {
"previous": "xxx",
"next": "xxx"
}
}"
}
]
此响应来自批处理调用。如果我分别调用它们,我可以轻松地遍历响应,并从中获取所有内容。但是,当我批量调用它们时,我无法通过“body”,我需要使用批量调用。
console.log(response[0].body);
将返回响应第一部分正文console.log(response[0].body.data);
内的对象,但返回undefined。我只是不明白。这应该很简单,但就像门上有锁而我没有正确的钥匙。
我通常没有问题遍历对象,所以我不需要一个通用的答案。我需要帮助才能看到这里我看不到的东西。为什么当我在body之后调用任何内容时控制台显示undefined,我需要做什么才能获得这些值中的任何一个?