cjson库的基本使用
这里有4个使用案例
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cJSON.h"
//基础使用
// int main()
{
cJSON *root = NULL, *person = NULL;
char *str_print = NULL;
/* 创建cJSON对象 */
root = cJSON_CreateObject(); /* 创建一个cJSON对象,要用 cJSON_Delete 释放内存 */
person = cJSON_CreateObject(); /* 创建子对象 */
/* 添加json节点 */
cJSON_AddItemToObject(root, "person", person);
cJSON_AddStringToObject(person, "firstName", "Lebron");
cJSON_AddStringToObject(person, "lastName", "James");
cJSON_AddNumberToObject(person, "age", 36);
cJSON_AddNumberToObject(person, "height", 206);
cJSON_AddStringToObject(root, "team", "Lakers");
/* 打印 */
str_print = cJSON_Print(root);
printf("\nsize:%d\n"