所以我想做的是在密码硬币之间得到实时价格,直到一些身份证明出现了破折号,问题才出现。

这是代码
var btcbnb, ethbnb, usdtbnb, usdcbnb, ltcbnb;
var btcln, ethcln, usdtcln, usdccln, ltcln, bnbln ,bch;
var liveprice11 = {
"async": true,
"scroosDomain": true,
"url": "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin%2Cethereum%2Cusd%2Clitecoin%2Cbinancecoin%2Cbinance-peg-bitcoin-cash&vs_currencies=bnb%2Clink%2Cusd",
"method": "GET",
"headers": {}
}
$.ajax(liveprice11).done(function (response){
btcbnb = response.bitcoin.bnb;
ethbnb = response.ethereum.bnb;
usdtbnb = response.ethereum.bnb;
usdcbnb = response.usd.bnb;
ltcbnb = response.usd.bnb;
// link
btcln = response.bitcoin.link;
ethcln = response.ethereum.link;
usdtcln = response.usd.link;
usdccln = response.usd.link;
ltcln = response.litecoin.link;
bnbln = response.binancecoin.link;
bch = response.binance-peg-bitcoin-cash.usd;
console.log(bch);
});这是有问题的线路
bch = response.binance-peg-bitcoin-cash.usd;真希望有人能帮忙,谢谢
发布于 2022-10-04 03:26:21
正如您所发现的,JS不允许您访问具有这种破折号的对象成员的名称。
一个简单的解决办法是
bch = response['binance-peg-bitcoin-cash'].usd;https://stackoverflow.com/questions/73942677
复制相似问题