字符长度
char *reporte_connect_ok(void)
{
cJSON *root;
char *out;
char name0[125];
char str_value0[125];
char macaddr[20];
char ipaddr[30];
root=cJSON_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");
out=cJSON_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;
root=cJSON_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));
out=cJSON_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 subitem
printf("subitem %d\n",subitem->valueint);
}
阅读(7026) | 评论(0) | 转发(0) |