ML302-OpenCpu开发CJSON的示例分析
今天就跟大家聊聊有关ML302-OpenCpu开发CJSON的示例分析,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
我们提供的服务有:网站建设、做网站、微信公众号开发、网站优化、网站认证、古蔺ssl等。为成百上千企事业单位解决了网站和推广的问题。提供周到的售前咨询和贴心的售后服务,是有科学管理、有技术的古蔺网站制作公司
中移4G模块-ML302-OpenCpu开发-CJSON
JSON转字符串
cJSON *root=NULL; cJSON *sub_js=NULL; char *out=NULL; root = cJSON_CreateObject(); cJSON_AddStringToObject(root, "version", "V1.1.0"); cJSON_AddStringToObject(root, "imei", "1xxxxxxxxxxxxxxxx"); cJSON_AddItemToObject(root, "data", sub_js = cJSON_CreateObject()); cJSON_AddNumberToObject(sub_js, "status", 1); cJSON_AddTrueToObject(sub_js, "material"); cJSON_AddTrueToObject(sub_js, "power_on"); cJSON_AddNumberToObject(sub_js, "qty", 123); cJSON_AddStringToObject(root, "dt", "2020-01-07T05:15:52"); out=cJSON_Print(root); cJSON_Delete(root); cm_printf("[CJSON]:\n"); cm_printf("%s\n",out); cJSON_free(out);
字符串转JSON
char * json = "{ \"json\" : { \"id\":1, \"nodeId\":11, \"deviceId\":111, \"deviceName\":\"aaa\", \"ieee\":\"01212\", \"ep\":\"1111\", \"type\":\"bbb\" }}"; char * json1 = "{\"id\":1, \"nodeId\":11, \"deviceId\":111, \"deviceName\":\"aaa\"}"; cJSON * root; cJSON * format; int value_int; char * value_string; root = cJSON_Parse(json); format = cJSON_GetObjectItem(root,"json"); value_int = cJSON_GetObjectItem(format,"nodeId")->valueint; value_string = cJSON_GetObjectItem(format,"ieee")->valuestring; cm_printf( "%d\n", value_int ); cm_printf( "%s\n", value_string ); cJSON_Delete(root); root = cJSON_Parse(json1); value_int = cJSON_GetObjectItem(root,"id")->valueint; value_string = cJSON_GetObjectItem(root,"deviceName")->valuestring; cm_printf( "%d\n", value_int ); cm_printf( "%s\n", value_string ); cJSON_Delete(root);
看完上述内容,你们对ML302-OpenCpu开发CJSON的示例分析有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注创新互联行业资讯频道,感谢大家的支持。
网页名称:ML302-OpenCpu开发CJSON的示例分析
文章网址:http://myzitong.com/article/ghoocj.html