【问题标题】:Uncaught SyntaxError: Unexpected token o- JSON.ParseUncaught SyntaxError: Unexpected token o- JSON.Parse
【发布时间】:2014-09-24 11:27:26
【问题描述】:

我使用 openexchangerates api 来获取汇率值。 var t = JSON.parse(json.rates); 有什么问题? 我得到“未捕获的语法错误:意外的令牌 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);
    }
});
});

【问题讨论】:

  • 当你 console.log(json) 时,你得到了什么?

标签: javascript json


【解决方案1】:

您无需使用JSON.parse 解析任何内容。错误

Uncaught SyntaxError: Unexpected token o

表示json.rates 已经是您可以使用的对象。这是有道理的,因为这就是 JSONP 的工作方式:在后台执行一些函数,并在其中传递一些 javascript 对象。

【讨论】:

    猜你喜欢
    • 2015-07-01
    • 2013-10-14
    • 2013-09-29
    • 2013-12-21
    • 1970-01-01
    • 1970-01-01
    • 2012-05-17
    • 2019-02-10
    • 2014-07-08
    相关资源
    最近更新 更多