小编MRI*_*I80的帖子

POSTed JSON to Google Apps Script,需要提取值并放置在 Google Sheets 中

我正在向 Google Apps Script 发布 JSON,并希望在 Google 表格中显示该 JSON 中的特定值。

我使用以下代码从这篇文章中获取数据到我的工作表中

function doPost(e) {
    Logger.log("I was called")
    if (typeof e !== 'undefined')
        Logger.log(e.parameter);
    var ss = SpreadsheetApp.openById("ID here")
    var sheet = ss.getSheetByName("Sheet1")
    sheet.getRange(1, 1).setValue(JSON.stringify(e))
    return ContentService.createTextOutput(JSON.stringify(e))
}
Run Code Online (Sandbox Code Playgroud)

我的工作表现在显示:

{
   "parameter":{

   },
   "contextPath":"",
   "contentLength":20,
   "queryString":"",
   "parameters":{

   },
   "postData":{
      "type":"application/json",
      "length":20,
      "contents":"{\"myValue\":13}",
      "name":"postData"
   }
}
Run Code Online (Sandbox Code Playgroud)

我只希望它显示 myValue 的值——在这个例子中是数字 13。

我已经尝试了这些论坛上建议的许多内容,我想我是通过这篇文章中的解决方案到达那里,并将代码更改为:

function doPost(e) {
    Logger.log("I was called")
    if (typeof e !== 'undefined')
        Logger.log(e.parameter);
    var jsonString = e.postData.getDataAsString(); …
Run Code Online (Sandbox Code Playgroud)

javascript google-apps-script

2
推荐指数
1
解决办法
3569
查看次数

标签 统计

google-apps-script ×1

javascript ×1