簡體   English   中英

解析有效的JSON時出現'Uncaught SyntaxError:Unexpected token:'

[英]'Uncaught SyntaxError: Unexpected token :' when parsing valid JSON

我正在從外部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消費。

另請參見此處- 嘗試調用API的$ .getJSON parsererror

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM