I am new to the C language. I need to append two json_object
arrays created with the json-c
library. This is my code:
struct json_object *obj1,*array1,*array2,*array3;
obj1 = json_object_new_object();
array1 = json_object_new_array();
json_object_array_add(array1, json_object_new_int(1));
json_object_array_add(array1, json_object_new_int(2));
json_object_array_add(array1, json_object_new_int(3));
json_object_object_add(obj1, "array1", array1);
array2 = json_object_new_array();
json_object_array_add(array2, json_object_new_int(4));
json_object_array_add(array2, json_object_new_int(5));
json_object_array_add(array2, json_object_new_int(6));
json_object_object_add(obj1, "array2", array2);
json_object_object_add(obj1, "array3", array1+array2);
But I got the following error:
error: invalid operands to binary + (have ‘struct json_object *’ and ‘struct json_object *’) json_object_object_add(obj1, "array3", array1+array2);
Is this not possible? I need output like this:
{
"array1:[1,2,3],
"array2":[4,5,6],
"array3":[1,2,3,4,5,6]
}
Or is it possible to add a normal C integer array to Json, like this
int32_t smp[100]={0};
smp[0] = 1;
smp[1] = 2;
smp[2] = 3;
smp[3] = 4;
smp[4] = 5;
smp[5] = 6;
json_object_object_add(obj1, "array3", smp);
array1+array2
isn't possible in C.