今天就跟大家聊聊有关ML302-OpenCpu开发CJSON的示例分析,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
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);
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的示例分析有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注亿速云行业资讯频道,感谢大家的支持。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。