在使用CJSON创建字符没有问题,但是创建数字是一直是显示0,代码如下:
/*
* Create a json format data
*/
root = cJSON_CreateObject();
if (root == NULL) {
os_printf("cJson create obj error!!n");
vTaskDelete(NULL);
return;
}
cJSON_AddStringToObject(root,"msg_type","no
tify");
services = cJSON_CreateObject();
if (services == NULL) {
os_printf("cjson create services error!!n");
vTaskDelete(NULL);
cJSON_Delete(root);
return;
}
cJSON_AddItemToObject(root,"services",services);
ops = cJSON_CreateObject();
if (ops == NULL) {
os_printf("cjson create ops error!!n");
vTaskDelete(NULL);
cJSON_Delete(root);
cJSON_Delete(services);
return;
}
cJSON_AddItemToObject(services,"operation_status",ops);
cJSON_AddNumberToObject(ops,"status",1L);
li = cJSON_CreateObject();
if (li == NULL) {
os_printf("cjson create ops error!!n");
vTaskDelete(NULL);
cJSON_Delete(root);
cJSON_Delete(services);
cJSON_Delete(li);
return;
}
cJSON_AddItemToObject(services,"lightbulb",li);
cJSON_AddNumberToObject(li,"alpha",122L);
cJSON_AddNumberToObject(li,"color_rgb",122L);
cJSON_AddNumberToObject(li,"color_hsl",122L);
jsonStr = cJSON_Print(root);
os_printf("json data = %sn",jsonStr);
打印结果如下:
json data = {
"msg_type": "notify",
"services": {
"operation_status": {
"status": 0
},
"lightbulb": {
"alpha": 0,
"color_rgb": 0,
"color_hsl": 0
}
}
}
数字全部是0,请问这是怎么回事?用的SDK是ESP8266_RTOS_SDK-master.zip,是2016/2/20下载的