您好,登錄后才能下訂單哦!
今天就跟大家聊聊有關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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。