2つの仮想通貨取引所からレートを取得しようとしています。
ソースコードは下記です。
function doGet() {
var bb_response = UrlFetchApp.fetch("https://public.bitbank.cc/btc_jpy/ticker");
var bb_json = JSON.parse(bb_response.getContentText());
var cmc_response = UrlFetchApp.fetch("https://api.coinmarketcap.com/v1/ticker/cyder/?convert=JPY")
var cmc_json = JSON.parse(cmc_response.getContentText());
var html = HtmlService.createTemplateFromFile('index.html');
html.msg = bb_json["data"]["sell"] + cmc_json["price_btc"];
return html.evaluate();
}
これを実行しますと、
1640500undefined
など、前半のbb_json["data"]["sell"] のデータは返ってきますが、
後半のcmc_json["price_btc"]はundefinedとなってしまいます。
ちなみに、bb_responseのデータは
{"success":1,"data":{"sell":"1656075","buy":"1648612","high":"1859999","low":"1631458","last":"1648603","vol":"431.8903","timestamp":1515713476821}}
であり、
cmc_responseのデータは
[
{
"id": "cyder",
"name": "Cyder",
"symbol": "CYDER",
"rank": "1178",
"price_usd": "0.0290929",
"price_btc": "0.00000220",
"24h_volume_usd": "106166.0",
"market_cap_usd": null,
"available_supply": null,
"total_supply": "80000000.0",
"max_supply": null,
"percent_change_1h": "-2.5",
"percent_change_24h": "-8.69",
"percent_change_7d": "3424.82",
"last_updated": "1515712754",
"price_jpy": "3.239785344",
"24h_volume_jpy": "11822645.76",
"market_cap_jpy": null
}
]
となっています。
大かっこ[]が原因ではないかと思っていろいろ試しているのですが、
undefinedのままです。
初歩的なことかもしれませんが、ご教示いただければ幸いです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/01/11 23:41