"response.data" API 后如何获取数据



我不知道在response.data之后获得API的所有数据的正确代码是什么。我使用以太坊API。下面是我的代码:

global.etherminepool = `https://api.ethermine.org/poolStats`;
axios.get(etherminepool)
.then(function(response) {
// handle success

console.log(response.data); // I tried "response.data.price.eur". Do I have to use () or []?
})
.catch(function (error) {
// handle error
console.log(error);
})
.then(function () {
// always executed
});

当我尝试response.data.price.eur的错误是:TypeError: Cannot read property 'eur' of undefinedresponse.data.price也不起作用。response.data的响应是:

{
status: 'OK',
data: {
topMiners: [],       
minedBlocks: [       
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object], [Object],
[Object], [Object]
],
poolStats: {
hashRate: 180365172843161.53,
miners: 320965,
workers: 980198,
blocksPerHour: 68.92
},
price: {
time: '2021-10-10T10:09:56.000Z',
usd: 3580.5,
btc: 0.0650543794,
eur: 3094.580078125,
cny: 23070,
rub: 257127
},
estimates: {
time: '2021-10-10T10:09:56.000Z',
blockReward: 2.1481,
hashrate: 695958780441595,
blockTime: 13.5318,
gasPrice: 59.0492384812
}
}
}

正如@J_K所写,正确的方法是"response.data.data.price.eur">

相关内容

  • 没有找到相关文章

最新更新