简体   繁体   English

Uncaught SyntaxError:意外的令牌o- JSON.Parse

[英]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.

相关问题 Uncaught SyntaxError:意外的令牌o-JSON.Parse - Uncaught SyntaxError: Unexpected token o - JSON.Parse 未捕获到的SyntaxError:意外令牌[与JSON.parse - Uncaught SyntaxError: Unexpected token [ with JSON.parse "未捕获的 SyntaxError:带有 JSON.parse 的意外标记" - Uncaught SyntaxError: Unexpected token with JSON.parse JSON.parse 错误(未捕获的 SyntaxError:JSON 中的意外标记 o 在 position 1) - JSON.parse error (Uncaught SyntaxError: Unexpected token o in JSON at position 1) 获取&#39;未捕获的SyntaxError:意外的令牌o <unknown file> :使用JSON.parse时为1&#39; - Getting 'Uncaught SyntaxError: Unexpected token o in <unknown file>:1' when using JSON.parse 未捕获到的SyntaxError:JSON中的意外令牌u在JSON.parse的位置0 - Uncaught SyntaxError: Unexpected token u in JSON at position 0 at JSON.parse 未捕获的SyntaxError:JSON.parse中位置0的JSON中的意外标记a( <anonymous> ) - Uncaught SyntaxError: Unexpected token a in JSON at position 0 at JSON.parse (<anonymous>) 未捕获到的SyntaxError:JSON中的意外令牌&lt;在JSON.parse位置0处( <anonymous> ) - Uncaught SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse (<anonymous>) Uncaught SyntaxError: Unexpected token & in JSON at position 1 at JSON.parse (<anonymous> )</anonymous> - Uncaught SyntaxError: Unexpected token & in JSON at position 1 at JSON.parse (<anonymous>) Javascript JSON.parse:Uncaught SyntaxError:意外的令牌N. - Javascript JSON.parse: Uncaught SyntaxError: Unexpected token N
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM