从JSON API接收错误的值

时间:2017-07-06 05:35:53

标签: javascript arrays json api

我有以下代码:

var urlKraken1 = "https://api.kraken.com/0/public/OHLC?pair=XBTUSD&interval=1";
request({
    url: urlKraken1,
    json: true
}, function (error, response, body) {
    if (!error && response.statusCode === 200) {
        var valuesArray = [];           
        var cur = body.result.XXBTZUSD.length -1;       
        var time = body.result.XXBTZUSD[cur][0];
        var high = body.result.XXBTZUSD[cur][2];
        var low = body.result.XXBTZUSD[cur][3];
        var open = body.result.XXBTZUSD[cur][1];
        var close = body.result.XXBTZUSD[cur][4];
        var volume = body.result.XXBTZUSD[cur][6];
        var Currency1 = "BTC";
        var Currency2 = "USD";
        valuesArray.push([time, "kraken.com", Currency1, Currency2, high, low, open, close, volume]);
        writeMultiRows("kraken.com", Currency1, valuesArray);
} 

但是在我的数据库中,我得到的值与API中的值不一致。 我收到的数据例如:

time = 1499280240 
high = 2609.001
low = 2608.666
open = 2609.001
close = 2608.666
volume= 12.42484963

但我应该收到:

time = 1499280240
high = 2610.000
low = 2605.022
open = 2609.001
close = 2610.000
volume= 15.42483298

提前感谢各种提示和帮助!

1 个答案:

答案 0 :(得分:1)

您的分配错误的数据。 按f12并打开网络选项卡并检查网络响应以查看确切数据... 相应地分配数组......