Reputation: 493
I use openexchangerates api to get exchange rates value. What is wrong wih var t = JSON.parse(json.rates);? I get 'Uncaught SyntaxError: Unexpected token o' To check
$( document ).ready(function() {
$.ajax({
url: 'http://openexchangerates.org/api/latest.json?app_id=xxxxxxxxxxxxxxxxxxxxx',
dataType: 'jsonp',
success: function(json) {
var t = JSON.parse(json.rates);
console.log(t);
}
});
});
Upvotes: 0
Views: 1992
Reputation: 193261
You don't need to parse anything with JSON.parse
. Error
Uncaught SyntaxError: Unexpected token o
means that json.rates
is already an object you can use. And it makes sense because this is how JSONP works: some function is executed behind the scene and some javascript object is passed in it.
Upvotes: 2