1

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. 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? 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.

Talysson
  • 1,363
  • 1
  • 9
  • 13

2 Answers2

0

Your format string aa{ss} is for an "array of array of dicts of string keys and string values" --- note the double array. 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(...)

Michael Gratton
  • 516
  • 2
  • 10
  • I tried that and got `failed to parse value of type 'a{ss}': 1-43:can not parse as value of type '{ss}'. This entire file has been ignored.`, it seems that my format string is correct (I created it based on [this](https://people.gnome.org/~ryanl/glib-docs/gvariant-format-strings.html#gvariant-format-strings-dictionaries), where it seems to imply that in `a{sv}` is the whole dictionary because a dictionary is just an array of arrays). – Talysson Dec 12 '17 at 10:57
0

I discovered the problem was that somehow my settings instance wasn't being initialized correctly when created inside a static construct block. Moving the creation of that to a memoized method solved the problem.

Talysson
  • 1,363
  • 1
  • 9
  • 13