2012-12-19 50 views
3

我想知道如何使用YQL获取JSON数据。使用YQL为Facebook获取JSON数据

这是我的JSON网址:

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

在这里http://developer.yahoo.com/yql/console/。我不知道如何使用它 – sami

回答

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" 
     } 
    }); 
}); 

中的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/

+0

它工作吗?否 – sami

+0

只有在浏览器控制台中查看结果才会显示结果。 – PhearOfRayne

+0

你能纠正它与html输出的工作吗? – sami

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'); 
      } 
); 

A simple demo here

+0

感谢@arttronics :) –

+0

那我给定的网址?你可以使用我给定的网址做一个小提琴吗? – sami

+0

@sami:** Steven Farley **已经完成了这项工作...... –