//节点类型
#define cJSON_Invalid (0)
#define cJSON_False (1 << 0)
#define cJSON_True (1 << 1)
#define cJSON_NULL (1 << 2)
#define cJSON_Number (1 << 3)
#define cJSON_String (1 << 4)
#define cJSON_Array (1 << 5)
#define cJSON_Object (1 << 6)
#define cJSON_Raw (1 << 7) /* raw json */
//节点结构体定义
typedef struct cJSON //表示一个json节点
{
/* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
struct cJSON *next; //节点的下一个节点
struct cJSON *prev; //节点的上一个节点
/* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
struct cJSON *child; //节点的子节点
/* The type of the item, as above. */
int type; //就是上面的节点类型
/* The item's string, if type==cJSON_String and type == cJSON_Raw */
char *valuestring;
/* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */
int valueint;
/* The item's number, if type==cJSON_Number */
double valuedouble;
/* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
char *string;
} cJSON;
解码(parse)
/* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */
/* Supply a block of JSON, and this returns a cJSON object you can interrogate. */
//把json字符串解析为节点树对象,即解码
CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value);
编码(print)
/* Render a cJSON entity to text for transfer/storage. */
//把节点对象输出成json字符串,有格式化
CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item);
/* Render a cJSON entity to text for transfer/storage without any formatting. */
//把节点变量输出成json字符串,不带格式化
CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item);