将nomonics crypto api和Javascript与googlesheets电子表格结合使用,返回的对象为:
[
{
"circulating_supply": "17591362",
"high": "24436.29525000",
"high_timestamp": "2018-01-05T00:00:00.000Z",
"market_cap": "70647474650.63",
"max_supply": "21000000",
"price": "4016.03211000",
"currency": "BTC",
"1d": {
"market_cap_change": "2334344443.63",
"market_cap_change_pct": "0.0342",
"price_change": "132.26230000",
"price_change_pct": "0.0341",
"volume": "531837882.13",
"volume_change": "34633070.11",
"volume_change_pct": "0.0697"
},
"7d": {
"market_cap_change": "2087829209.46",
"market_cap_change_pct": "0.0305",
"price_change": "115.88873000",
"price_change_pct": "0.0297",
"volume": "2984154293.31",
"volume_change": "-872155432.42",
"volume_change_pct": "-0.2262"
},
"rank": "1"
}
]
我可以通过以下方式查看价格
resp[0].price
但是当我尝试访问1d和7d部分时,我已经尝试过:
resp[0].1d.market_cap_change
和
resp[0]1d.market_cap_change
googlesheets不允许我保存错误代码:
Missing name after . operator. (line 29, file "Code")
访问1d和7d块中元素的正确方法是什么?
谢谢。
答案 0 :(得分:0)
您需要使用[]
表示法,因为您的密钥不是valid JS identifier
resp[0]['1d'].market_cap_change
let resp = [{"circulating_supply": "17591362","high": "24436.29525000","high_timestamp": "2018-01-05T00:00:00.000Z","market_cap": "70647474650.63","max_supply": "21000000","price": "4016.03211000","currency": "BTC","1d": {"market_cap_change": "2334344443.63","market_cap_change_pct": "0.0342","price_change":"132.26230000","price_change_pct": "0.0341","volume": "531837882.13","volume_change": "34633070.11","volume_change_pct": "0.0697"},"7d": {"market_cap_change": "2087829209.46","market_cap_change_pct": "0.0305","price_change": "115.88873000","price_change_pct": "0.0297","volume": "2984154293.31","volume_change": "-872155432.42","volume_change_pct": "-0.2262"},"rank": "1"}]
console.log(resp[0]['1d'].market_cap_change)