since: 2.28


g_variant_lookup_value (
  GVariant* dictionary,
  const gchar* key,
  const GVariantType* expected_type


Looks up a value in a dictionary GVariant.

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 value 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 GVariantDict may be more efficient.

Available since: 2.28



Type: const gchar*

The key to look up in the dictionary.

The data is owned by the caller of the function.
The value is a NUL terminated UTF-8 string.

Type: GVariantType

A GVariantType, or NULL.

The argument can be NULL.
The data is owned by the caller of the function.

Return value

Type: GVariant

The value of the dictionary key, or NULL.

The caller of the method takes ownership of the data, and is responsible for freeing it.