【发布时间】:2016-05-28 14:34:57
【问题描述】:
我正在尝试使用 jquery 读取 JSON 数据。具体来说,我正在尝试从此网址读取 JSON:http://mkweb.bcgsc.ca/color-summarizer/?url=http://scontent-a.cdninstagram.com/hphotos-xfa1/t51.2885-15/10643840_701797013239098_657737630_a.jpg&precision=low&num_clusters=3&json=1&callback=?
但是我不断收到此错误:
Uncaught SyntaxError: Unexpected token :
这是我的jQuery:
$(document).ready(function () {
var one = "1"
$.getJSON('http://mkweb.bcgsc.ca/color-summarizer/?url=http://scontent-a.cdninstagram.com/hphotos-xfa1/t51.2885-15/10643840_701797013239098_657737630_a.jpg&precision=low&num_clusters=3&json=1&callback=?', function(result) {
document.write(result.clusters.one.rgb[0]);
});
});
我在 JSON 代码的第一个冒号处收到错误消息。
据我了解,JSON 数据实际上是作为 Javascript 读取的。我该如何解决这个问题。
【问题讨论】:
-
该url不支持JSONP或者至少不支持提供
callback=xyz参数。 -
不相关,但您的
var one技巧不起作用。您需要使用result.clusters[one].rgb[0]或result.clusters['1'].rgb[0] -
我添加了回调=?参数,因为我之前收到此错误
No 'Access-Control-Allow-Origin' header is present on the requested resource.
标签: javascript jquery json