我正在从外部url解析JSON数据,但是由于出现'Uncaught SyntaxError:Unexpected token:'语法错误而无法使用该数据。我检查了JSONLint上的JSON并验证了它的正确性,所以我不知道自己可能做错了什么。

我从以下网址获取它:

http://clipped.me/algorithm/clippedapi.php?url=http://www.bbc.com/news/world-asia-china-30067035&callback=

像这样解析它:

$.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示例。

最佳答案

看起来clipped.me正在忽略您的回调,而只是将原始JSON转储到DOM中,而不是将格式正确的JSONP回调转储到DOM中。如果失败,它将生成语法错误消息。他们的API也不支持跨域。看起来它被设计为仅从服务器端代码消费,而不是从客户端JS消费。

另请参见此处-$.getJSON parsererror trying to call API

09-08 02:42