【发布时间】: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 层数据的脚本。谁能帮我找到正确的资源?
【问题讨论】:
-
对于初学者,您必须迭代 JSON 对象,然后将数据粘贴到电子表格行中。您可以通过一次粘贴一行或一次转储一个数组来执行此操作。参考以下链接 1.stackoverflow.com/a/19324092/3157062 2.developers.google.com/apps-script/reference/spreadsheet/…
标签: arrays json rest google-apps-script google-sheets