2 Star 2 Fork 0

干饭小白/轮子

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
test_json.cpp 1.86 KB
一键复制 编辑 原始数据 按行查看 历史
干饭小白 提交于 2023-04-21 06:26 . yyjson接口封装
#include "myJson.h"
#include "yyjson.h"
#include <iostream>
int main(void)
{
//------------------JSON-------------------//
MyJson *my_Json = new MyJson;
my_Json->Init(_WRITE_JSON_);
my_Json->AddRootKeyStr("cmd", "get_channel_listܼ");
void *arr = my_Json->CreatJsonArrNum(NULL, 0);
my_Json->AddRootArr(arr, "data");
void *obj = my_Json->CreatJsonObj();
my_Json->AddObjKeyStr(obj, "taskid", "112201602");
my_Json->AddObjKeyStr(obj, "taskname","K259+520_HD");
my_Json->AddObjKeyStr(obj, "address", "192.168.11.41");
my_Json->AddObjKeyStr(obj, "cameraip", "192.168.2.221");
my_Json->AddObjKeyNum(obj, "no", 1);
my_Json->AddObjKeyNum(obj, "run_stat", 1);
my_Json->AddObjKeyNum(obj, "link_stat", 1);
my_Json->AddObjKeyNum(obj, "conn_num", 0);
my_Json->AddArrVal(arr, obj);
char buf[2048] = { 0 };
my_Json->printJsonStr(buf);
//printf("%s\n", buf);
my_Json->Free();
//--------------------JSON------------------//
MyJson *pause_Json = new MyJson;
pause_Json->Init(_PAUSE_JSON_, buf);
char ans[1024] = { 0 };
pause_Json->PauseRootKeyStr("cmd", ans, 1024);
printf("%s\n", ans);
void* arr_obj = pause_Json->PauseRootKeyArr("data");
void* obj_buf[1];
pause_Json->PauseArrElemObj(arr_obj, obj_buf, 1);
/*printf("%s\n", pause_Json->PauseObjElemStr(obj_buf[0], "taskid"));
printf("%s\n", pause_Json->PauseObjElemStr(obj_buf[0], "taskname"));
printf("%s\n", pause_Json->PauseObjElemStr(obj_buf[0], "address"));
printf("%s\n", pause_Json->PauseObjElemStr(obj_buf[0], "cameraip"));*/
printf("%d\n", pause_Json->PauseObjElemNum(obj_buf[0], "no"));
printf("%d\n", pause_Json->PauseObjElemNum(obj_buf[0], "run_stat"));
printf("%d\n", pause_Json->PauseObjElemNum(obj_buf[0], "link_stat"));
printf("%d\n", pause_Json->PauseObjElemNum(obj_buf[0], "conn_num"));
pause_Json->Free();
getchar();
return 0;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/chenMr-Errr113/wheel.git
git@gitee.com:chenMr-Errr113/wheel.git
chenMr-Errr113
wheel
轮子
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385