Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1154085
  • 博文数量: 241
  • 博客积分: 10
  • 博客等级: 民兵
  • 技术积分: 2279
  • 用 户 组: 普通用户
  • 注册时间: 2012-11-27 19:53
个人简介

JustForFun

文章分类

全部博文(241)

文章存档

2023年(8)

2022年(2)

2021年(3)

2020年(30)

2019年(11)

2018年(27)

2017年(54)

2016年(83)

2015年(23)

我的朋友

分类: LINUX

2017-07-17 18:28:25

字符长度
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);
      }

阅读(6883) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~