我是 C 语言的新手。我需要附加使用库json_object
创建的两个数组。json-c
这是我的代码:
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);
但我收到以下错误:
错误:二进制 + 的无效操作数(有 'struct json_object *' 和 'struct json_object *') json_object_object_add(obj1, "array3", array1+array2);
这不可能吗?我需要这样的输出:
{
"array1:[1,2,3],
"array2":[4,5,6],
"array3":[1,2,3,4,5,6]
}
或者是否可以向Json添加一个普通的C整数数组,像这样
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);