简体   繁体   English

Google Apps脚本中的JSON

[英]JSON in Google Apps Script

I am trying to validate a webhook with Podio ( https://developers.podio.com/doc/hooks/validate-hook-verificated-215241 ) using google apps script. 我正在尝试使用Google Apps脚本与Podio( https://developers.podio.com/doc/hooks/validate-hook-verificated-215241 )验证Webhook。

Currently I have the following script successfully writing data to a document (after the Podio Post is activated): 目前,我有以下脚本已成功将数据写入文档(在激活Podio Post之后):

function doPost(l) {
  var doc = DocumentApp.openById('1to3-JzhE27-LK0Zw7hEsdYgiSd7xQq7jjp13m6YwRh0');
  var jstring = Utilities.jsonStringify(l);
  doc.appendParagraph(jstring);
}

With the data appearing as follows: 数据显示如下:

{"queryString":null,"parameter":{"hook_id":"38035","code":"a92e06a2","type":"hook.verify"},"contextPath":"","parameters":{"hook_id":["38035"],"code":["a92e06a2"],"type":["hook.verify"]},"contentLength":44}

For some reason, google apps script won't let me take this data and access the properties like this: 由于某些原因,Google Apps脚本不允许我获取此数据并访问如下属性:

jstring.parameter.code;

If I copy the (seemingly) JSON string into a separate script under a new variable, I can then access the data within the JSON. 如果我将(看似)JSON字符串复制到新变量下的单独脚本中,则可以访问JSON中的数据。

What am I doing wrong here? 我在这里做错了什么?

It looks like you have a JavaScript object that you convert to a JSON string, jstring . 看起来您有一个转换为JSON字符串jstring的JavaScript对象。 It is just a string. 它只是一个字符串。 If you want to access the properties represented in the string, use the original object, l . 如果要访问字符串中表示的属性,请使用原始对象l Ie, l.parameter.code l.parameter.code

function doPost(l) {
  var doc = DocumentApp.openById('1to3-JzhE27-LK0Zw7hEsdYgiSd7xQq7jjp13m6YwRh0');
  var jstring = Utilities.jsonStringify(l);
  doc.appendParagraph(jstring);
  dosomething(l.parameter.code);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM