Assuming the following JSON object, an array of [epoch, value] arrays:
[ [0,1], [1912312314,2], [1912312857,5] ]
What's the correct way to remove an element of the array ? The idea is to remove the one with an epoch alder than a given value. I use json-c 0.11.
I tried :
json_object *jsonHeatmapObj;
jsonHeatmapObj = json_tokener_parse ( "[ [0,1], [1912312314,2], [1912312857,5] ]" );
for ( int idx=0 ; idx < json_object_array_length(jsonHeatmapObj) ; idx++ ) {
json_object *curJsonHeatpointObj = json_object_array_get_idx ( jsonHeatmapObj , idx );
int x = json_object_get_int ( json_object_array_get_idx ( curJsonHeatpointObj , 0 ) );
if ( x < time(NULL) - 10 ) {
json_object_put ( curJsonHeatpointObj );
}
printf("\t[%d]=%s\n", idx, json_object_to_json_string(jsonHeatmapObj));
}
This fails (SIGSEGV) when calling json_object_to_json_string() with the adjusted object.
Thank you