如何在Google App脚本的“属性服务"中将2D数组保存到脚本属性? [英] How to save a 2D array to a Script Property in Properties Service in Google App Script?
问题描述
我有一个2D数组,需要将其另存为Google App脚本中的属性.我该怎么做?
I have a 2D array that I need to save as a property in Google App Script. How would I do this?
var array = [['value 1', 1.0, 'A'],['value 2', 2.0, 'B'],['value 3', 3.0, 'C']]
PropertiesService.getScriptProperties().setProperty('myArray', array)
运行上面列出的代码时,我得到[Ljava.lang.Object;@40ac055f
作为值.
When I run the code as listed above I get [Ljava.lang.Object;@40ac055f
as the value.
当我使用array.toString()
时,属性值使方括号无效.
When I us array.toString()
the property value negates the square brackets.
提前谢谢!
推荐答案
-
请注意,属性存储用于保存特定的属性和键值.这并不是要替换整个电子表格.
Note that Properties Store is meant to save specific properties and key values. It's not meant to be a replacement for the entire spreadsheet.
当前配额 1 将每个键的属性值大小限制为9kB,将每个商店的总存储量限制为500kB.
Current quotas1 limit the property value size per key to 9kB and total storage per store to 500kB.
如果您的要求没有超出上述限制,那么简单的方法是使用JSON.stringify
If your requirement doesn't cross the limit described above, the easy way is to use JSON.stringify2, Which will convert it to a parsable string.
var array = [['value 1', 1.0, 'A'],['value 2', 2.0, 'B'],['value 3', 3.0, 'C']]; var jarray = JSON.stringify(array); PropertiesService.getScriptProperties().setProperty('myArray', jarray);
You can then use JSON.parse3 to retrieve the array
var array = JSON.parse(jarray);
这篇关于如何在Google App脚本的“属性服务"中将2D数组保存到脚本属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!