我有一个脚本(javascript),我用它来通过YQL提取数据。当我将原始查询放入YQL控制台时,一切正常,但在我的脚本中使用提供的URL,我会得到不同的结果。
请在此处查看:http://jsfiddle.net/thetuneupguy/t2JCB/
$(function() {
$.getJSON('http://query.yahooapis.com/v1/public/yql?q=SELECT%20*%20FROM%20yahoo.finance.quotes%20WHERE%20symbol%20in(%22GCF14.CMX%22%2C%22SIF14.CMX%22%2C%22PAH14.NYM%22%2C%22PLF14.NYM%22)&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=?', function(data) {
var items = [];
console.log(data);
$.each(data, function() {
$.each(this, function(name, value) {
/// Do what ever here...
items.push('<li id="' + name + '">' + value + '</li>');
console.log(name + '=' + value);
});
});
$('<ul/>', {
'class': 'my-new-list',
html: items.join('')
}).appendTo('body');
});
});
我做错了什么想法?
答案 0 :(得分:0)
$(function() {
$.getJSON('http://query.yahooapis.com/v1/public/yql?q=SELECT%20*%20FROM%20yahoo.finance.quotes%20WHERE%20symbol%20in(%22GCF14.CMX%22%2C%22SIF14.CMX%22%2C%22PAH14.NYM%22%2C%22PLF14.NYM%22)&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=?', function(data) {
console.log(data.query.results.quote);
$.each(data.query.results.quote,function(key,val){
var items = [];
$.each(val,function(name,value){
items.push('<li id="' + name + '">' + value + '</li>');
});
$('<ul/>', {'class': 'my-new-list',html: items.join('')}).appendTo('body');
});
});
});
这应该让你走上正轨。 quote
object
更深一些。