#include
#include
cJSON *cjson_link(char *J1, char *J2)
{
cJSON *root1 = cJSON_Parse(J1);
cJSON *root2 = cJSON_Parse(J2);
cJSON *res_root = cJSON_CreateObject();
cJSON *item1 = root1->child;
cJSON *item2 = root2->child;
while(item1)
{
cJSON_AddStringToObject(res_root, item1->string, item1->valuestring);
item1 = item1->next;
}
while(item2)
{
cJSON_AddStringToObject(res_root, item2->string, item2->valuestring);
item1 = item1->next;
}
cJSON_Delete(root1);
cJSON_Delete(root2);
return res_root;
}
int main()
{
char json1[64] = "{\"name\":\"kunkun\",\"id\":\"123456\"}";
char json2[64] = "{\"score\":\"90\",\"address\":\"127.0.0.1\"}";
cJSON *student = cjson_link(json1, json2);
char *out = cJSON_Print(student);
printf("%s\n",out);
free(out);
cJSON_Delete(student);
return 0;
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)