我正在解析对“net.connman.Manager.GetServices”函数的响应,如下所示:
<method name="GetServices">
<arg name="services" type="a(oa{sv})" direction="out"/>
</method>
这是一个相当复杂的结构。
到目前为止我得到的是:
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 );
那么,我如何访问内部数组数据?
我试过这个: GVariantIter * iter2; g_variant_get(data,“a {sv}”,&amp; iter2); GVariant * child2 = g_variant_iter_next_value(iter2);
但它失败并出现一些对齐错误:
**
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
答案 0 :(得分:2)
data
应该有GVariantIter*
,而不是GVariant*
(您将GVariant格式字符串作为第二个参数传递给{{1} }})。
您可以使用GVariant Format Strings来简化代码:
g_variant_get()