【问题标题】:How do I get REST API JSON data and extract them to Google Spreadsheet as a table?如何获取 REST API JSON 数据并将它们作为表格提取到 Google 电子表格?
【发布时间】:2018-10-03 04:18:13
【问题描述】:

我们使用 AskNicely 来确定我们的 NetPromoter 得分,方法是发送调查并使用我们从回复中获得的数据衡量我们的绩效。然后我们提取响应并获取下面的示例 JSON 数据:

{
  "success": true,
  "total": "14836",
  "totalpages": "2968",
  "pagenumber": "1",
  "pagesize": "50000",
  "since_time": "0",
  "data": [
    {
      "response_id": "20352",
      "person_id": "11007",
      "name": "Mark Williams",
      "email": "markwilliams_23@hotmail.com",
      "answer": "5",
      "answerlabel": "5",
      "data": null,
      "comment": "Response time is too long. But was able to resolve my issue",
      "note": null,
      "status": "",
      "dontcontact": null,
      "sent": "2018-10-03 08:53:21",
      "opened": "2018-10-03 08:53:21",
      "responded": "2018-10-03 09:21:30",
      "lastemailed": "2018-10-03 08:53:21",
      "created": "2018-10-03 08:53:02",
      "segment": "",
      "published": "",
      "publishedname": "-",
      "publishedavatar": null,
      "customernumber_c": "171502",
      "companyname_c": "Williams, Mark",
      "agentname_c": "MICHAEL S",
      "city_c": "RIDGEHAVEN",
      "segment_b_c": null,
      "state_c": "SA",
      "workflow_custom_alerts_c": null,
      "workflow_check_for_publish_c": null,
      "workflow_detractor_alerts_c": null,
      "company_c": null,
      "segment_a_c": null,
      "deliverymethod": "email",
      "dashboard": "recommend",
      "email_token": "568e62f94c"
    },
    {
      "response_id": "20351",
      "person_id": "11006",
      "name": "Susie White",
      "email": "Whites61@bigpond.net.au",
      "answer": "9",
      "answerlabel": "9",
      "data": null,
      "comment": "Best service i've gotten so far!",
      "note": null,
      "status": "",
      "dontcontact": null,
      "sent": "2018-10-03 08:53:21",
      "opened": "2018-10-03 08:53:21",
      "responded": "2018-10-03 08:53:21",
      "lastemailed": "2018-10-03 08:53:21",
      "created": "2018-10-03 08:53:02",
      "segment": "",
      "published": "",
      "publishedname": "-",
      "publishedavatar": null,
      "customernumber_c": "171382",
      "companyname_c": "White, Susie",
      "agentname_c": "SAM N",
      "city_c": "Magill",
      "segment_b_c": null,
      "state_c": "SA",
      "workflow_custom_alerts_c": null,
      "workflow_check_for_publish_c": null,
      "workflow_detractor_alerts_c": null,
      "company_c": null,
      "segment_a_c": null,
      "deliverymethod": "email",
      "dashboard": "recommend",
      "email_token": "e257aab272"
    },

我可以使用以下脚本成功提取数据:

function callAPI() {

// Call the Numbers API for random math fact
var response = UrlFetchApp.fetch("insert URL");
var a = response.getContentText();
Logger.log(a);   
}

但这就是我的知识范围。我需要的是在“数据”中提取每个项目并将标签作为第 1 行的表头,然后每行提取和粘贴它们的值。我一直在搜索 stackoverflow 和谷歌,但到目前为止,我所看到的只是获取 1 层数据的脚本。谁能帮我找到正确的资源?

【问题讨论】:

标签: arrays json rest google-apps-script google-sheets


【解决方案1】:

我能够找到一个完美运行的代码。来自ImportJSON by Trevor Lohrbeer

但我使用的是旧版本。不知道为什么它对我有用:Version 1.1

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多