我正在尝试使用 Fetch() 导入 json 文件来填充多个 Google 工作表
我已经尝试了几个小时,但我不知道如何做到这一点
json 是动态的,所以它的数据总是在变化,但它的结构保持不变
我的 json 看起来像
{
"connections": [
{
"Id": 131527,
"From": 49647,
"To": 49644,
"Name From": "Horus Max",
"Name To": "Bob allison",
"Initial Date": "9/21/2020 15:20",
"Last Date": "9/21/2020 15:20",
"Type": "",
"Weight": 0,
"Checkbox ZZZ": "",
"Text Area": "",
"Radio AAA": "value one AAA",
"Select bbb": "value one sss"
},
{
},
],
"elements": [
{
"Id": 49645,
"Type": "Person",
"Label": "Sally Yager",
"First Name": "Sally",
"Last Name": "Yager",
"Description": "",
"Segment": "555",
"Image": null,
"Project Name": "test222",
"Initial Date": "09/29/2020 17:44",
"Last Date": "09/29/2020 17:47",
"Issues Checkbox": [
"Option 1",
"Option 6"
],
"IssuesRadio": "Option 3",
"Notes": "222"
},
{
}
],
"name": "My project name"
}
我需要将元素数据传递到名为 elements 的工作表中,并将连接数据解析到名为 Connections 的工作表中
Elements sheet
Connections sheet
我得到什么
I have
//=fetchdata("https://sum-app.net/projects/14312620200623668/download_data/kumu_json")
async function fetchdata(url) {
var response = await UrlFetchApp.fetch(url);
var responseText = await response.getContentText();
var responseJson = JSON.parse(responseText);
// Return something to display in the Google Sheet.
var rows = [Object.keys(responseJson)]; // Retrieve headers.
var temp = [];
for (var i = 0; i < rows[0].length; i++) {
temp.push(responseJson[rows[0][i]]); // Retrieve values.
}
rows.push(temp);
return temp
}
这是一张谷歌表格,其中包含我得到的内容和期望的结果https://docs.google.com/spreadsheets/d/14vxiueXsUzFtkw22RHA7qVFE--PFVSwfj4zJIU7I3nk/edit?usp=sharing
Thanks