I know I must be missing something really simple here. What is the correct way to parse arrays using Jansson?
My data structure looks like this: {"distance1": [0, 1, 2, ...], ...}. Each array may have an arbitrary amount of those integers. If needed I can pass the array length to my JSON.
Currently I'm extracting the data like this:
int distance1[10000];
int distance2[10000];
int ambient_light[10000];
int sound_pressure_level[10000];
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));
As soon as I add another property there (ie. {s:o, s:o} and "distance2") things start to fall apart. I keep getting EXC_BAD_ACCESS. Here's a trace:
(gdb) run sine 1000 tmp/sensors.json Starting program: /Users/juhovepsalainen/Projects/Koodilehto/lightpylon/elovalo/build/exporte r/exporter sine 1000 tmp/sensors.json
Program received signal EXC_BAD_ACCESS, Could not access memory. Reason: KERN_INVALID_ADDRESS at address: 0x000000000000000e 0x000000010000e191 in unpack () (gdb) bt #0 0x000000010000e191 in unpack () #1 0x000000010000dba7 in unpack () #2 0x000000010000e379 in json_vunpack_ex () #3 0x000000010000e4a5 in json_unpack () #4 0x0000000100003fa1 in export_effect () #5 0x0000000100003e81 in main ()