下你所需,载你所想!
汇集开发技术源码资料

cjson代码

:16.492KB :1 :2022-10-08 14:22:18

部分简介

cjson代码如果开发者对于本文件有需要的可以参考。
c语言解析json和打包json的源码库
简单的使用例子
解析json
cJSON *js_root,*js_obj,*js_array,*js_ch;
int i=0;
QString dev_id;
int num;
int re=0;
int len;
int j=0;
js_root = cJSON_Parse(msg_src);
js_array = cJSON_GetObjectItem(js_root,"cmd");
len = cJSON_GetArraySize(js_array);
for(i=0;i {
js_obj = cJSON_GetArrayItem(js_array,i);
js_ch = cJSON_GetObjectItem(js_obj,"devid");
dev_id = js_ch->valuestring;
js_ch = cJSON_GetObjectItem(js_obj,"num");
num = js_ch->valueint;
re = dev_conf->AddDev(dev_id,num);
for(j=0;jdev_connect_list.size();j )//检查本id号是不是本次搜索到的
{
if(dev_id == dev_conf->dev_connect_list.at(j).dev_id)
{
SendHeadId(BIN_CMD_CONNECT_BACK,(u8*)dev_conf->dev_connect_list.at(i).zig_netid,
dev_conf->CheckId());//直接同意入网
break;
}
}
}
cJSON_Delete(js_root);
打包json
cJSON *js_root,*js_obj;
if(js == NULL)return;
js_root = js;
js_obj = cJSON_CreateObject();
cJSON_AddItemToObject(js_root,"head",js_obj);
cJSON_AddNumberToObject(js_obj,"cmd",cmd_t);

热门推荐

相关文章