【发布时间】:2021-05-09 21:50:00
【问题描述】:
我正在使用 Fetch 将 JSON 数据输出到谷歌表格
Fetch 函数没有将 JSON 中的所有数据输出到工作表中
您可以看到 N 到 R 的列未添加到工作表中
这是我的 Fetch 函数
function fetchData() {
// Set Fetch Variables
var url = "https://sum-app.net/projects/13435720200118544/download_data/combined_json"
var response = UrlFetchApp.fetch(url);
var responseText = response.getContentText();
var responseJson = JSON.parse(responseText);
var connectionKeys = Object.keys(responseJson.connections[0]);
var data = responseJson.connections.map(e => connectionKeys.map(f => {
return e[f] instanceof Array ? e[f].join("|") : e[f];
}));
data.unshift(connectionKeys);
data = data.map(x => x.map(y => typeof y === 'undefined' || null ? "" : y));
const ss=SpreadsheetApp.getActive();
const sh=ss.getActiveSheet();
sh.clearContents();//clear sheet
sh.getRange(1,1,data.length,data[0].length).setValues(data);//load the data
}
这是 JSON:
https://sum-app.net/projects/13435720200118544/download_data/combined_json
如果有帮助,这里有一个带有 Fetch 功能的 Google 表格 https://docs.google.com/spreadsheets/d/1CuP2DDO-rB1henrMAurBgb-CYmh7RNBbSHOjF6BqG5c/edit?usp=sharing
提前感谢您在获取 fetchData 函数以输出 JSON 中的所有数据方面提供的任何帮助
【问题讨论】:
标签: javascript google-apps-script google-sheets fetch