简体   繁体   中英

Uncaught SyntaxError: Unexpected token o- JSON.Parse

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);
    }
});
});

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM