3

YQLを使用してJSONデータをフェッチする方法を知りたいです。

これは私のJSONURLです:

https://www.facebook.com/feeds/page.php?id=397319800348866&format=json
4

2 に答える 2

6

jQuery を使用した簡単な例を次に示します。

$(function () {
    $.ajax({
        url: "http://query.yahooapis.com/v1/public/yql",
        dataType: "jsonp",
        success: function (data) {
            console.log(data.query.results.json);
            $.each(data.query.results.json.entries, function (i, v) {
                //console.log(data.query.results.json.entries[i]);
                $('#entries').append(data.query.results.json.entries[i].title + '<br />');
            });
        }, data: {
            q: 'select * from json where url="https://www.facebook.com/feeds/page.php?id=397319800348866&format=json"',
            format: "json"
        }
    });
});

上記の URL を含む console.log 内で、次の結果を取得できました。

entries: Array[29]
icon: "http://www.facebook.com/favicon.ico"
link: "http://www.facebook.com/"
self: "https://www.facebook.com/feeds/page.php?id=397319800348866&format=json"
title: "Doers Inc's Facebook Wall"
updated: "2012-12-19T01:08:44-08:00"

参照用の作業例: http://jsfiddle.net/DtNxb/1/

于 2012-12-19T09:13:35.137 に答える
2

jQuery.getJSONを使えば思ったより簡単です。

これを試して:

$.getJSON("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22your_url&format=json",
          function(data) {
              var id = data.query.results.div;
              $('#table').append('<li>'+id.h1+'</li>');
              $('#table').listview('refresh');
          }
);

簡単なデモはこちら

于 2012-12-19T09:10:16.413 に答える