[英]Uncaught SyntaxError: Unexpected token o- JSON.Parse
I use openexchangerates api to get exchange rates value. 我使用openexchangerates api获取汇率值。 What is wrong wih var t = JSON.parse(json.rates);? var t = JSON.parse(json.rates);是什么错误? I get 'Uncaught SyntaxError: Unexpected token o' To check 我收到“未捕获的SyntaxError:意外令牌o”来检查
$( 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
. 您不需要使用JSON.parse
解析任何内容。 Error 错误
Uncaught SyntaxError: Unexpected token o
means that json.rates
is already an object you can use. 表示json.rates
已经是您可以使用的对象。 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. 这是有道理的,因为这就是JSONP的工作方式:某些函数在后台执行,而一些javascript对象则在其中传递。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.