[cpp]
<span style="font-size:16px;">JSONNODE *arrn = json_new(JSON_ARRAY);
json_set_name(n, NULL);
json_push_back(n, json_new_a(NULL, "one"));
json_push_back(n, json_new_a(NULL, "汉字"));
json_push_back(n, json_new_i(NULL, 999999));
json_char *arrjc = json_write(arrn);
CCLOG("Json: %s, %d", arrjc, strlen(jc));</span>
<span style="font-size:16px;">JSONNODE *arrn = json_new(JSON_ARRAY);
json_set_name(n, NULL);
json_push_back(n, json_new_a(NULL, "one"));
json_push_back(n, json_new_a(NULL, "汉字"));
json_push_back(n, json_new_i(NULL, 999999));
json_char *arrjc = json_write(arrn);
CCLOG("Json: %s, %d", arrjc, strlen(jc));</span>
需要注意的是如果不想要“键”,则将对应参数设置为NULL,对象中不能这样做,数组中可以
特别PS:如果希望汉字原样输出,而不转化成utf-8编码格式,需要将JSONOptions.h中的宏关闭
[cpp] view plaincopyprint?<span style="font-size:16px;">#define JSON_ESCAPE_WRITES</span>
<span style="font-size:16px;">#define JSON_ESCAPE_WRITES</span>
代码下载
5-24记录:libjson中判断结点类型c方法json_type(const void *node)
已定义类型
[cpp]
#define JSON_NULL '\0'
#define JSON_STRING '\1'
#define JSON_NUMBER '\2'
#define JSON_BOOL '\3'
#define JSON_ARRAY '\4'
#define JSON_NODE '\5'
#define JSON_NULL '\0'
#define JSON_STRING '\1'
#define JSON_NUMBER '\2'
#define JSON_BOOL '\3'
#define JSON_ARRAY '\4'
#define JSON_NODE '\5'
作者:oneRain88
相关阅读: