我正在解析来自外部网址的JSON数据,但由于“未捕获的语法错误:未预料到的令牌”而无法使用数据:'语法错误。我检查了JSONLint上的JSON,它验证没问题,所以我不知道自己做错了什么。
我是从这个网址获取的:
解析它:
$.getJSON("http://clipped.me/algorithm/clippedapi.php?url=http://www.bbc.com/news/world-asia-china-30067035&callback=?", function(data) {
var story = data.summary[0];
console.log(story);
$('p').html(story)
});
收到的数据是:
{
"title": "BBC News - Hong Kong protest leaders denied Beijing flight",
"summary": [
"They had hoped to meet China's leaders as part of their push for greater democracy, but were told at the airport that their travel permits were invalid.",
"They want Beijing to allow more candidates to stand in the territory's next leadership election in 2017.",
"The group were greeted at the airport by fellow democracy activists, who unfurled yellow umbrellas - a symbol of Hong Kong's democracy movement."
],
"source": "bbc.com"
}
以下是JSFIDDLE示例。
答案 0 :(得分:2)
看起来像clipped.me忽略了你的回调,只是将原始JSON转储到DOM而不是正确格式化的JSONP回调。当失败时,它会生成语法错误消息。它们的API也不支持跨源。看起来它只是从服务器端代码中使用,而不是客户端JS。