Google JavaScript表单属性JSON from变量

q1qsirdb  于 12个月前  发布在  Go
关注(0)|答案(1)|浏览(214)

在使用Coinmarketcap.com API的Google表格中,我试图下载数据。为此,我有一个循环,我想从先前创建的表中删除后续名称。

var listaCrypto = "BTC,ETH,ADA";
  var tabCrypto = listaCrypto.split(",");
  

for (var i = 1; tabCrypto[i]; i++) {
  
    var url='https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest?symbol='+tabCrypto[i];
    var result= UrlFetchApp.fetch(url, requestOptions);
    
    var txt= result.getContentText();
    var d=JSON.parse(txt); 
  
    lista1.getRange(start_row + rankBTC, 1).setValue(d.data.tabCrypto[i].name);  //<-- this doesn't
    lista1.getRange(start_row + rankBTC, 2).setValue(d.data.BTC.name);  //<-- this line works
  }

字符串

azpvetkf

azpvetkf1#

可以使用以下语法object["property_name"]object检索属性property_name

var listaCrypto = "BTC,ETH,ADA";
  var tabCrypto = listaCrypto.split(",");

for (var i = 0; i<tabCrypto.length; i++) {
    var symbol = tabCrypto[i];
    var url='https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest?symbol='+tabCrypto[i];
    var result= UrlFetchApp.fetch(url, requestOptions);

    var txt= result.getContentText();
    var d=JSON.parse(txt); 

    lista1.getRange(start_row + rankBTC, 1).setValue(d.data[symbol].name);  //<-- this doesn't
    lista1.getRange(start_row + rankBTC, 2).setValue(d.data.BTC.name);  //<-- this line works
}

字符串

相关问题