解析来自 Facebook Open Graph 的 JSONP 响应的正确语法
我使用对 Facebook Open Graph API 的一次调用来获取两组 JSONP 数据,但在解析响应时遇到了一些问题。
这是我的代码:
// The IDs to the fan pages to like
var likeURLs = ['71671905072','146175949904'];
// The base of the URL we will build to query the API
var reqURL = "http://graph.facebook.com/?ids=";
// Construct the rest of reqURL using our fan pages
for (var i=0; i < likeURLs.length; i++) {
reqURL += likeURLs[i];
if (i != (likeURLs.length - 1)) {reqURL += ',';} else {reqURL += "&callback=?"}
};
function getLikes(){
$.getJSON(reqURL, function(data){
console.dir(data);
});
}
getLikes();
数据已成功返回,但我对如何正确访问它有疑问。无论出于何种原因,data[0]
都不起作用,data.71671905072
也不起作用。有人能指出我正确的语法吗?已经很晚了,我的大脑不太运转。
I'm using one call to the Facebook Open Graph API to grab two sets of JSONP data, and having some trouble parsing the response.
Here's my code:
// The IDs to the fan pages to like
var likeURLs = ['71671905072','146175949904'];
// The base of the URL we will build to query the API
var reqURL = "http://graph.facebook.com/?ids=";
// Construct the rest of reqURL using our fan pages
for (var i=0; i < likeURLs.length; i++) {
reqURL += likeURLs[i];
if (i != (likeURLs.length - 1)) {reqURL += ',';} else {reqURL += "&callback=?"}
};
function getLikes(){
$.getJSON(reqURL, function(data){
console.dir(data);
});
}
getLikes();
The data is successfully returned, but I'm spacing on how to access it correctly. For whatever reason, data[0]
won't work, nor will data.71671905072
. Can anybody point me towards the right syntax? It's late and my brain is not working very well.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
data["71671905072"]
应该可以工作。data["71671905072"]
should work.