HI 乐鑫 :
在使用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","notify");
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 = %s\n",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下载的
THS
关于CJSON添加数字
Re: 关于CJSON添加数字
Postby ESP_Faye » Thu Apr 14, 2016 5:52 pm
您好,
ESP8266_IOT_PLATFORM 是基于 ESP8266_RTOS_SDK 的应用示例,您可以参考它使用 cJSON_AddNumberToObject。
感谢您对 ESP8266 的关注!
ESP8266_IOT_PLATFORM 是基于 ESP8266_RTOS_SDK 的应用示例,您可以参考它使用 cJSON_AddNumberToObject。
感谢您对 ESP8266 的关注!
Who is online
Users browsing this forum: No registered users and 3 guests
Login
Newbies Start Here
Are you new to ESP8266?
Unsure what to do?
Dunno where to start?
Start right here!
Latest SDK
Documentation
Complete listing of the official ESP8266 related documentation release by ESPRESSIF!
Must read here!
- All times are UTC+08:00
- Top
- Delete all board cookies
About Us
Espressif Systems is a fabless semiconductor company providing cutting-edge low power WiFi SoCs and wireless solutions for wireless communications and Internet of Things applications. We are the manufacturer of ESP8266EX.