为什么此UrlFetch函数无法正常工作? [英] Why is this UrlFetch function not working properly?

查看:72
本文介绍了为什么此UrlFetch函数无法正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我正在尝试通过Google电子表格图表上的JavaScript工具运行的功能,该功能当前在4个不同的网站上均有效,在此示例中:

This is the function I'm trying to run through the JavaScript Tool on my Google Spreadsheet chart, the function is currently working on 4 different websites, where in this example:

$ id是我的电子表格单元格(belacoin)中导入的值

$id is the imported value from my spreadsheet cell (belacoin)

function CoinmarketcapPrice($id) {
  var response = UrlFetchApp.fetch("https://api.coinmarketcap.com/v1/ticker/" + $id);
  var html = JSON.parse(response.getContentText());
  try 
  {
    return parseFloat(html["price_btc"]);
  }
  catch(err)
  {
    return null;
  }
}

这是UrlFetch返回的内容:

this is what that UrlFetch returns:

[
    {
        "id": "belacoin", 
        "name": "BelaCoin", 
        "symbol": "BELA", 
        "rank": "176", 
        "price_usd": "0.212823", 
        "price_btc": "0.00008400", 
        "24h_volume_usd": "534995.0", 
        "market_cap_usd": "7694903.0", 
        "available_supply": "36156350.0", 
        "total_supply": "36156350.0", 
        "percent_change_1h": "0.63", 
        "percent_change_24h": "1.88", 
        "percent_change_7d": "-17.03", 
        "last_updated": "1499549044"
    }
]

推荐答案

尝试html.price_btc或html [0] .price_btc

try html.price_btc or html[0].price_btc

这篇关于为什么此UrlFetch函数无法正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆