GLib.Variant.prototype.lookup_value
function lookup_value(key: String, expected_type: GLib.VariantType): GLib.Variant { // Gjs wrapper for g_variant_lookup_value() }
Looks up a value in a dictionary GLib.Variant.
This function works with dictionaries of the type a{s*} (and equally well with type a{o*}, but we only further discuss the string case for sake of clarity).
In the event that dictionary has the type a{sv}, the expected_type string specifies what type of value is expected to be inside of the variant. If the value inside the variant has a different type then null is returned. In the event that dictionary has a value type other than v then expected_type must directly match the key type and it is used to unpack the value directly or an error occurs.
In either case, if key is not found in dictionary, null is returned.
If the key is found and the value has the correct type, it is returned. If expected_type was specified then any non-null return value will have this type.
This function is currently implemented with a linear scan. If you plan to do many lookups then GLib.VariantDict may be more efficient.
Since 2.28
- key
the key to lookup in the dictionary
- expected_type
a GLib.VariantType, or null
- Returns
the value of the dictionary key, or null