1
var url = 'https://graph.facebook.com/?ids=http://www.stackoverflow.com';

$.getJSON(url, function(resp) {
  $("p").html('comments = ' + resp.comments);
});

これにより、次の html が my に配置されます<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 に答える