1
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 不容易解析。谢谢!

4

2 回答 2

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

于 2012-05-24T18:06:40.733 回答
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);
        })
    });
于 2012-05-24T18:46:40.993 回答