getJson 并解析以创建列表(目前) jQuery/Yahoo Finance API
我几乎可以正常工作了,但我无法解决解析问题。如果有人可以帮助我将非常感激!
我正在尝试查询 Yahoo Finance API 并使用 jQuery 解析结果。这是我执行此操作的代码:
<script>
$(document).ready(function(){
var url = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20WHERE%20symbol%3D'NPO'&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback";
$.getJSON(url + "&format=json&jsoncallback=?", function(data) {
var items = [];
$.each(data, function(key, val) {
items.push('<li id="' + key + '">' + val + '</li>');
});
$('<ul/>', {
'class': 'my-new-list',
html: items.join('')
}).appendTo('body');
});
});
</script>
但我收到此错误:
任何克服此错误的帮助将不胜感激。
谢谢!
I almost have the thing working but I can't get past a parsing issue. If anyone can help I would be very thankful!
I am trying to query Yahoo Finance API and parse the results using jQuery. Here is my code to do so:
<script>
$(document).ready(function(){
var url = "http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20WHERE%20symbol%3D'NPO'&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback";
$.getJSON(url + "&format=json&jsoncallback=?", function(data) {
var items = [];
$.each(data, function(key, val) {
items.push('<li id="' + key + '">' + val + '</li>');
});
$('<ul/>', {
'class': 'my-new-list',
html: items.join('')
}).appendTo('body');
});
});
</script>
But I am getting this error:
Any help overcoming this error would be much appreciated.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
jsoncallback
参数。getJSON()
添加的format
参数已在url
中指定items
数组将对象存储为数据位于data.query.results.quote
下试试这个:
工作代码是 这里。
jsoncallback
parameter is not used by the service.callback
parameter. It is added by thegetJSON()
format
parameter is already specified inurl
items
array is storing objects as the data are underdata.query.results.quote
Try this:
Working code is HERE.
YQL 使用
callback=?
参数,而不是jsoncallback=?
尝试以下操作:编辑:注意,url 也必须更改。
YQL uses a
callback=?
parameter, notjsoncallback=?
try this:Edit: Note, the url had to change too.
当您删除
&jsoncallback=?
时,对我来说效果很好。实际上,主字符串中已经有了
format=json
。JSFIDDLE 演示
Works fine for me when you remove the
&jsoncallback=?
.You actually already have the
format=json
in the main string.JSFIDDLE DEMO