Juho Vepsäläinen wrote:
> Hi,
Hello.
> json_unpack(root, "{s:[i], s:[i], s:[i], s:[i]}",
> "distance1", distance1,
> "distance2", distance2,
> "ambient_light", ambient_light,
> "sound_pressure", sound_pressure_level
> );
When using [i], only the first item is indeed extracted. What you
should be doing is to extract the array as-is using the 'o' format
specifier.
json_t *distance1, *distance2, *ambient_light; *sound_pressure_level;
json_unpack(root, "{s:o, s:o, s:o, s:o}",
"distance1", distance1,
"distance2", distance2,
"ambient_light", ambient_light,
"sound_pressure", sound_pressure_level);
Then you can use the json_array_*() functions to access the items of
the array. For example, to store the values to a normal C array, you
would do this:
size_t i;
int *distance1_values = malloc(json_array_size(distance1) * sizeof(int));
for(i = 0; i < json_array_length(distance1); i++)
distance1_values[i] = json_integer_value(json_array_get(dinstance1, i));
Hope this helps :)
Petri