I have a script to get all the data from a Binance and push out parsed information. Here's my script:
function myFunction() {
var sh = SpreadsheetApp.getActiveSpreadsheet();
var ss = sh.getActiveSheet();
var data = UrlFetchApp.fetch("https://www.binance.com/assetWithdraw/getAllAsset.html");
var first = JSON.parse(data)[0];
var out = JSON.stringify(first).split(",");
for(var i =0;i<out.length;i++){
Logger.log(i);
Logger.log(out[i]);
ss.getRange(1,i+1).setValue(out[i]);
}
}
I received information that looks like "title":"value". I need to get all the "title" values as column headers and then the values as the rows. I'm not sure where to go from here.
How about this modification?
Modification points :
setValues()
.Modified script :
Reference :
If I misunderstand your question, please tell me. I would like to modify it.
Edit 1 :
In order to retrieve keys from object which is
out[0]
, I usedfor (var i in out[0]) {
. Please see the following samples.Sample 1 :
ResultIn this script,
sample[0]
is an object of{key1: "value1", key2: "value2"}
.for (var i in sample[0]) {
can retrieve keys which arekey1
andkey2
. Using retrieved keys,value1
andvalue2
can be retrieved bysample[0][i]
.On the other hand, please see the next sample script.
Sample 2 :
In this script,
sample[0].length
becomesundefined
. Becauseobject.length
cannot retrieve the length. So this for loop doesn't work.If you want to retrieve keys and values using for loop like the sample 2. Please use the next sample script.
Sample 3 :
ResultIn this script, keys from object can be retrieved by
Object.keys()
. Using this, keys and values are retrieved.Reference :
Edit 2 :