解析JSON - 应该很简单。我错过了什么?

时间:2014-03-02 04:41:54

标签: jquery json coinbase-php coinbase-api

我正在尝试解析Coinbase API以撤回比特币的当前价格。这是我的代码:

http://jsfiddle.net/9Kx5N/20/

var mtgoxAPI = "https://coinbase.com/api/v1/prices/spot_rate";
$.getJSON(mtgoxAPI, function (json) {
      // Set the variables from the results array
      var price = json.amount;
      // Set the table td text
      $('#btc-price').text(price);
});

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:3)

尝试使用jsonp来回避原点废话:

var mtgoxAPI = "https://coinbase.com/api/v1/prices/spot_rate?callback=?";

$.getJSON(mtgoxAPI, null, function (json) {

    // Set the variables from the results array
    var price = json.amount;


    // Set the table td text
    $('#btc-price').text(price);

});

作品! coinbase API支持jsonp,jQuery可以告诉你在看到

时想要jsonp
"?callback=?"

在网址末尾。