CJSON源码分析
CJSON的数据结构
/* The cJSON structure: */
typedef struct cJSON
{
/* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem next/prev结构体指针允许你遍历数组/对象链。或者使用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. 一个数组/对象会有一个child指针,指向数组/对象中的头结点*/
struct cJSON *child;
/* The type of the item, as above. 本JSON项的类型*/
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. 本CJSON项的名称,若本项是一个OBJECT的下级,或其内容,会拥有名称;如{"name":"hany"}, "hany"是一个string型的JSON值,而它的名称是"name" */
char *string;
} cJSON;
常见JSON串
空串
{}
简单情况
{"name":"hany", "age":18}
一般情况
{
"users":[
{"uid":123},
{"uid":456}
]
}