简体   繁体   中英

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.

FB.api('me/friends', function(response) {});

I want to parse "response" into an array I tried response.forEach ...

I got:

Uncaught TypeError: friendsObject.forEach is not a function

So I thought I could just do 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.

I am super confused why the object cant turn into an array, wont parse but prints the entire object when I console.log it.

How do I parse that object into a javascript array?

Always use console.log to see the actual content of the response object. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM