简体   繁体   English

如何使用Vala从GSettings中存储的字典数组中读取值?

[英]How can I read a value from an array of dictionaries stored in GSettings with Vala?

The GSettings Vala docs are not very detailed and I can't find a way to read an item from an array of dictionaries stored in GSettings. GSettings Vala文档不是很详细,我找不到从GSettings中存储的字典数组中读取项目的方法。 Right now I have this in my schema: 现在我的架构中有这个:

<key type="aa{ss}" name="services">
    <default>[{"id": "postgresql", "name": "PostgreSQL"}]</default>
    <summary></summary>
    <description></description>
</key>

How can I read the values for the keys id and name of the first value of the services array? 如何读取键id的值和services数组的第一个值的name I tried a lot of possibilities (using get_value("services") then get_child(0) , for example) to read the dictionary but it simply breaks and I don't know how to debug it. 我尝试了很多可能性(例如,使用get_value("services")然后使用get_child(0) )来读取字典,但它只是坏了,我不知道如何调试它。

Your format string aa{ss} is for an "array of array of dicts of string keys and string values" --- note the double array. 您的格式字符串aa{ss}用于“字符串键和字符串值的字典数组的数组”-注意双精度数组。 You probably want just a{ss} , then you can access the dicts via get_child(0) as you were doing, then get lookup the values from the variant returned from that using lookup_value(...) 您可能只需要a{ss} ,然后就可以在执行操作时通过get_child(0)访问字典,然后使用lookup_value(...)从返回的变量中查找值lookup_value(...)

I discovered the problem was that somehow my settings instance wasn't being initialized correctly when created inside a static construct block. 我发现问题是在static construct块中创建我的设置实例时,由于某种原因未正确初始化。 Moving the creation of that to a memoized method solved the problem. 将其创建转移到记忆的方法即可解决该问题。

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

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