简体   繁体   English

Webdev Facebook API朋友返回对象数组[1],但是我无法通过javascript访问它

[英]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.

相关问题 无法访问 Javascript 中的对象/数组 - Cannot access object/array in Javascript Facebook API Javascript发布到朋友墙 - Facebook api Javascript post to friends wall javascript功能来获取朋友,facebook api? - javascript function for getting friends, facebook api? 如何存储用户朋友连接到变量或数组的Facebook图形api响应以供以后使用javascript使用 - How to store a facebook graph api response of users friends connections to a variable or array to use later using using javascript 无法访问通过 API 检索到的 object 属性,并显示错误消息 TypeError: Cannot read property '' of undefined - Nextjs/JavaScript - Cant access object properties retrieved via API with error message TypeError: Cannot read property '' of undefined - Nextjs/JavaScript 我有一个返回对象密钥的 function,但是我需要从此值访问原始 Object:Javascript - I have a function that returns an Object's key, however I need to access the original Object from this value: Javascript 我无权在Facebook API上获得所有invitable_friends - I don't have access to get all invitable_friends at Facebook API 如何在jsp文件中使用Javascript从Facebook API获取“获取朋友”列表 - How can I get Get friends list from Facebook API using Javascript in a jsp file Facebook Javascript邀请好友 - Facebook Javascript Inviting Friends 如何从 Javascript Facebook API 请求返回一个数组? - How to return an array from a Javascript Facebook API request?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM