将Javascript对象记录为字符串Google App脚本 [英] Log Javascript object as string Google App Scripts

查看:59
本文介绍了将Javascript对象记录为字符串Google App脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用Google App脚本中的Logger.log记录对象的内容?

Is there a way to log the contents of an object using Logger.log in Google App Scripts?

如果我有Logger.log(data),则日志为'DataTableBuilder'或'object'或类似的东西,并且无济于事.

If I have Logger.log(data), the log is 'DataTableBuilder', or 'object' or something similar and incredibly unhelpful.

如果可能的话,我想查看这些对象的JSON字符串...

I want to see JSON strings of these objects if possible...

推荐答案

2013年11月,您可以使用JSON.stringify()Objects转换为String.可以在此处中找到一些Google文档,而完整的JavaScript方法可在您首选的API参考上找到相关文档,例如 MDN .

As of Nov 2013, you can use JSON.stringify() to convert Objects into Strings. Some Google documentation can be found here, while the full JavaScript method documentation is available on your preferred API reference, such as MDN.

示例用法:

Logger.log(JSON.stringify(obj, null, 2));

或者,通过Stackdriver Logging(自 2017年6月开始):

Alternately, via Stackdriver Logging (as of 2017 June):

console.log({message: "Interactive object serialization", theObject: obj})
// or
console.log(JSON.stringify(obj));

这篇关于将Javascript对象记录为字符串Google App脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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