I am parsing the response to "net.connman.Manager.GetServices" function, which looks like this:
<method name="GetServices">
<arg name="services" type="a(oa{sv})" direction="out"/>
</method>
which is quite complex structure.
What I got so far is this:
GVariant* result = ... // response containing data
GVariantIter* iter1;
g_variant_get( result, "a(oa{sv})", &iter1 );
GVariant* child = g_variant_iter_next_value( iter1 );
while ( nullptr != child )
{
gchar* string;
GVariant* data;
g_variant_get( child, "(oa{sv})", &string, &data );
// how to access inner array?
g_variant_unref( child );
child = g_variant_iter_next_value( iter1 );
}
g_variant_iter_free( iter1 );
So, how do I access the inner array data?
I tried this: GVariantIter* iter2; g_variant_get( data, "a{sv}", &iter2 ); GVariant* child2 = g_variant_iter_next_value( iter2 );
but it fails with some alignment error:
**
GLib:ERROR:../../glib-2.48.2/glib/gvarianttypeinfo.c:163:g_variant_type_info_check: assertion failed: (info->alignment == 0 || info->alignment == 1 || info->alignment == 3 || info->alignment == 7)
Aborted
data
should have typeGVariantIter*
, notGVariant*
, as per the documentation for GVariant Format Strings (you are passing a GVariant format string as the second argument tog_variant_get()
).You can simplify the code quite a bit by using
g_variant_iter_loop()
though: