[英]Webdev Facebook API friends return an object array[1] however I cannot access it via javascript
I need help parsing the friendsList
object returned by [below] into JavaScript. 我需要将[以下]返回的friendsList
对象解析为JavaScript的帮助。
FB.api('me/friends', function(response) {});
I want to parse "response" into an array I tried response.forEach ...
我想将“响应”解析为我尝试过的数组response.forEach ...
I got: 我有:
Uncaught TypeError: friendsObject.forEach is not a function 未捕获的TypeError:friendsObject.forEach不是函数
So I thought I could just do JSON.parse(response);
所以我想我可以做JSON.parse(response);
that also gave me an error. 这也给了我一个错误。
Then I tried to print out with console.log(response)
as it gives me an Object. 然后我尝试使用console.log(response)
打印出来,因为它给了我一个Object。
I am super confused why the object cant turn into an array, wont parse but prints the entire object when I console.log it. 我非常困惑,为什么当我使用console.log对象时,对象无法变成数组,无法解析,但会打印整个对象。
How do I parse that object into a javascript array? 如何将该对象解析为javascript数组?
Always use console.log
to see the actual content of the response
object. 始终使用console.log
查看response
对象的实际内容。 It is usually an object with a "data" array, so it would be like this: 它通常是带有“数据”数组的对象,因此如下所示:
response.data.forEach...
Do not forget about error handling, response.data
can be undefined too. 不要忘记错误处理, response.data
也可以是未定义的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.