Ai
2 Star 11 Fork 2

寻根/jsonreflect

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
test.cpp 1.05 KB
一键复制 编辑 原始数据 按行查看 历史
寻根 提交于 2020-04-30 21:42 +08:00 . modified: test.cpp
#include "json.h"
JsonEntity(Item)
{
public:
//定义名为ival的int类型成员
rint(ival);
//定义名为bval的bool类型成员
rbool(bval);
//定义名为sval的string类型成员
rstring(sval);
};
JsonEntity(Entity)
{
public:
//定义名为ival的int类型成员
rint(ival);
//定义名为bval的bool类型成员
rbool(bval);
//定义名为sval的string类型成员
rstring(sval);
//定义名为list的vector<Item>类型成员
rarray(Item, list);
};
int main(int argc, char** argv)
{
Entity obj;
Entity tmp;
sp<Item> item;
obj.ival = 0;
obj.bval = false;
obj.sval = "zero";
item = obj.list.add();
item->ival = 1;
item->bval = true;
item->sval = "one";
item = obj.list.add();
item->ival = 2;
item->bval = true;
item->sval = "two";
item = obj.list.add();
item->ival = 3;
item->bval = true;
item->sval = "three";
//对象序列化为JSON字符串
cout << obj.toString() << endl << endl;
cout << endl;
//JSON字符串反序列化为对象
tmp.fromString(obj.toString());
cout << tmp.toString() << endl << endl;
return 0;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/xungen/jsonreflect.git
git@gitee.com:xungen/jsonreflect.git
xungen
jsonreflect
jsonreflect
master

搜索帮助