0
錯誤的價值觀,我有以下代碼:Recieving從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
預先感謝各種提示和幫助!
檢查瀏覽器開發人員工具網絡選項卡的請求 - 是來自服務器的正確數據?如果沒有,則客戶端代碼(您顯示的唯一代碼)不是問題 –
看起來應該是您當前正在獲取的「1499319720」,「2594.179」,「2594.179」,「2594.179」,「2594.179」,「 2594.179「,」0.10000000「,1'你想要最後的還是第二個值? - 對於倒數第二個值,使用'var cur = body.result.XXBTZUSD.length - 2' –