我有一个数组存储为GSettings中类型为a(ss)的GVariant,我想在肉桂Applet中使用它.我可以使用以下代码成功检索值:
I have an array stored as a GVariant of type a(ss) in GSettings, that I want to use in a Cinnamon Applet. I can retrieve the value successfully using the following code:
let schema = schema_source.lookup(SCHEMA_NAME, false); let settings = new Gio.Settings({ settings_schema: schema }); let my_value = settings.get_value('myvalue');但是我不能打开它的包装.据我所知,我可能需要使用GVariantIter结构将其解压缩,但文档有限,而且我无法在gjs API中找到正确的接口(如果确实存在).有人知道怎么做吗?
but I can't unpack it. As far as I can see, I will probably need to unpack it using a GVariantIter structure, but the documentation is limited, and I can't find the correct interface in the gjs API (if, indeed, it exists). Does anyone know how to do it?
谢谢!
修改: 我的架构如下:
<key type="a(ss)" name="myvalue"> <default>[]</default> <summary>an array of (string, string) tuples</summary> <description></description> </key>目前,我正在使用外部JSON文件存储设置,但这并不是100%令人满意的解决方案.我想我可以维护两个as类型的变量,并使它们保持对齐,但是必须有一种正确执行此操作的方法,对吗?
For the time being I'm using an external JSON file to store settings, but it's not a 100% satisfactory solution. I suppose I could maintain two as-type variables, and keep them aligned, but there must be a way to do this properly, right?
推荐答案有点晚,但是my_value.unpack()绝对可以.
A bit late, but my_value.unpack() works absolutely fine.
my_value.deep_unpack()将递归解压缩数组及其元素.
my_value.deep_unpack() will recursively unpack the arrays and their elements.
更多推荐
在javascript中解压缩GVariant
发布评论