cJSON的字符长度和字符比较以及数组
字符长度char *reporte_connect_ok(void){cJSON *root;char *out;char name0[125]; char str_value0[125]; char macaddr[20]; char ipaddr[30]; rootcJSON_CreateObject(); cJSON_AddStringToObject(root,Device,Gateway); get_mac_addr(macaddr); cJSON_AddStringToObject(root,MAC,macaddr); get_ip_addr(ipaddr); cJSON_AddStringToObject(root,IP,ipaddr); cJSON_AddStringToObject(root,Vendor,Hitouch); cJSON_AddStringToObject(root,Module,EasyShare S1); outcJSON_Print(root); cJSON_Delete(root); printf(out:%s\n,out); return out;}//这个函数在上面rep reporte_connect_ok();//是这样求json后面通过tcp发送的长度的len strlen(rep);write_client1((unsigned char *)rep,len);//值字符串比较cJSON *operation get_object_item(patch, “op”, case_sensitive);if (!cJSON_IsString(operation)){return INVALID;}if (strcmp(operation-valuestring, add) 0) { return ADD; } if (strcmp(operation-valuestring, remove) 0) { return REMOVE; } if (strcmp(operation-valuestring, replace) 0) { return REPLACE; }/////////////////////////////////////////////int buff[10];cJSON *root,*name,*item; char *out; rootcJSON_CreateObject(); buff[0] 0xaa; buff[1] 0x01; buff[2] 0x17; buff[3] 0x23; buff[4] 0x10; buff[5] 0x00; buff[6] 0x00; buff[7] 0x01; buff[8] \0; cJSON_AddStringToObject(root,from,USBSerial); cJSON_AddItemToObject(root, info, cJSON_CreateIntArray(buff, 9)); outcJSON_Print(root); cJSON_Delete(root); root cJSON_Parse(out); printf(%s,out); item cJSON_GetObjectItem(root,from); printf(from name-string%s\n,item-valuestring); item cJSON_GetObjectItem(root,info); int i;for (i 0; i cJSON_GetArraySize(item); i){cJSON *subitem cJSON_GetArrayItem(item, i); // handle subitemprintf(“subitem %d\n”,subitem-valueint);}
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2430176.html
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!