I have YAJL parsing me simple elements like given in the included example without a problem. (strings, integers, arrays, ...)
The example code can be found here: http://lloyd.github.io/yajl/yajl-2.0.1/example_2parse_config_8c-example.html
but now I have this type of JSON object:
{
"cmd":2,
"properties":
[
{
"idx":40,
"val":8813.602692
},
{
"idx":41,
"val":960
},
{
"idx":42,
"val":2
},
{
"idx":48,
"val":9
}
]
}
I can retrieve the command with (see the definitions of used variables in the linked example):
const char * path[] = {"cmd", (const char *) 0 };
yajl_val v = yajl_tree_get(ynode, path, yajl_t_number);
if (v)
*cmd = (commands)((int)YAJL_GET_INTEGER(v));
And I can get the reference to the properties array using:
int ar_sz;
const char * path[] = {"properties", (const char *) 0 };
yajl_val v = yajl_tree_get(ynode, path, yajl_t_array);
if (v)
{
ar_sz = v->u.array.len;
}
It gives me the correct array size, but I have no clue on how to retrieve the nested elements idx and val from the array elements.
Any help is very appreciated