在 Google Apps 脚本中,我通过 OAuth2 连接到服务。我收到一个 JSON 响应并对其进行解析,JSON.parse(response.getContentText());因此它会记录如下内容:
{Results=[{Id=45364743, Description=null, Name=Math I , IsActive=true},
{Id=45364768, Description=null, Name=Math II, IsActive=true}]}
Run Code Online (Sandbox Code Playgroud)
使用以下代码,我之前已获取 JSON 响应并将其成功写入 Google 表格。但是,这次 FOR 循环不会运行,因为dataSet没有length. 我猜这是因为所有内容都嵌套在“结果”下。
function getService2() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadsheet.getSheetByName('Data');
var key = 'kjeu7hjf7873alkjhehjhfayuluoojsds'
var options = {
method: "get",
headers: {
Authorization: "Bearer " + key,
api_key: key,
}
}
var response = UrlFetchApp.fetch(URL, options);
var dataAll = JSON.parse(response.getContentText());
var dataSet = dataAll;
Logger.log(dataSet)
var …Run Code Online (Sandbox Code Playgroud)