I would like to parse the gatecoin API JSON return.
They offer as an example return the following:
{
"tickers": [
{
"currencyPair": "BTCUSD",
"open": 200,
"last": 200,
"lastQ": 0.1,
"high": 200,
"low": 200,
"volume": 50,
"bid": 200,
"bidQ": 27.7099,
"ask": 203,
"askQ": 10,
"vwap": 0,
"createDateTime": "1421252904"
}
]
}
I would like to use BTCEUR as the currency pair, and I would like to then access the individual items. My code, in a Google sheet, is as follows:
function gatecoin()
{
var response = UrlFetchApp.fetch("https://api.gatecoin.com/Public/LiveTickers");
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Sheet1");
var json = JSON.parse(response.getContentText());
var rate = json.tickers.currencyPair["BTCEUR"].last
sheet.getRange(5, 2).setValue(rate);
}
I receive this error:
typeError: Cannot read property "BTCEUR" from undefined. (line 24, file "Code")
I have tried various other combinations like: tickers.currencyPair.BTCUSD.last and other variations with no success.
What is the correct way to do this?