var url = 'https://graph.facebook.com/?ids=http://www.stackoverflow.com';
$.getJSON(url, function(resp) {
$("p").html('comments = ' + resp.comments);
});
这会将以下html放在我的<p>
:comments = undefined
我从通话中得到的返回字符串是:
{
"http://www.thinlinebetween.com/tuesday-quote-of-the-day-jean-ingelow/": {
"id": "http://www.thinlinebetween.com/tuesday-quote-of-the-day-jean-ingelow/",
"shares": 2,
"comments": 1
}
}
我是否需要执行resp."http://www.thinlinebetween.com/tuesday-quote-of-the-day-jean-ingelow/".comments
之类的操作才能获得价值?返回的json不容易解析。谢谢!
答案 0 :(得分:0)
var postUrl = 'http://www.stackoverflow.com';
var apiUrl = 'https://graph.facebook.com/?ids=' + postUrl;
$.getJSON(apiUrl, function(resp) {
$("p").html('comments = ' + resp[postUrl].comments);
});
需要resp["http://www.stackoverflow.com"].comments
。
答案 1 :(得分:0)
这应该是方式,
$(function(){
var webUrl = 'http://www.stackoverflow.com';
var endpoint = 'https://graph.facebook.com';
$.getJSON(endpoint,{'ids':webUrl},function(response){
var comments = response[webUrl].comments;
$("p").html('comments = ' + comments);
})
});