Google Apps脚本中的JSON [英] JSON in Google Apps Script

查看:86
本文介绍了Google Apps脚本中的JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Podio验证webhook( https:// developers.podio.com/doc/hooks/validate-hook-verificated-215241 )使用谷歌应用程序脚本。

I am trying to validate a webhook with Podio (https://developers.podio.com/doc/hooks/validate-hook-verificated-215241) using google apps script.

目前我已成功编写以下脚本数据到文档(激活Podio Post后):

Currently I have the following script successfully writing data to a document (after the Podio Post is activated):

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

数据显示如下:

{"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:

jstring.parameter.code;

如果我将(看似)JSON字符串复制到新变量下的单独脚本中,我可以访问JSON中的数据。

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字符串的JavaScript对象, jstring 。它只是一个字符串。如果要访问字符串中表示的属性,请使用原始对象 l 。即, l.parameter.code

It looks like you have a JavaScript object that you convert to a JSON string, jstring. It is just a string. If you want to access the properties represented in the string, use the original object, l. Ie, 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);
}

这篇关于Google Apps脚本中的JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆