Reputation: 520
I'm parsing JSON data from an external url but failing to use the data because of an 'Uncaught SyntaxError: Unexpected token :' syntax error. I checked the JSON on JSONLint and it validated okay so I don't know what I could be doing wrong.
I'm getting it from this URL:
Parsing it like so:
$.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)
});
And the data received is this:
{
"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"
}
Here is a JSFIDDLE example.
Upvotes: 0
Views: 549
Reputation: 4492
It looks like clipped.me is ignoring your callback and simply dumping raw JSON into the DOM instead of a properly-formatted JSONP callback. When that fails it generates the syntax error message. Their API doesn't support cross-origin, either. It looks like it is designed to be consumed from server-side code only, not client-side JS.
See also here - $.getJSON parsererror trying to call API
Upvotes: 2