json11 c++ 用法
来源:互联网 发布:光环国际教育 大数据 编辑:程序博客网 时间:2024/06/16 00:20
json11 这个库是这两天看上去很好用的一个库,现在给出简单的用法,详细说明看官网
1. json 生成
// 生成 json
json11::Json my_json =json11::Json::object {
{ "key1","value1" },
{ "key2",false },
{ "key3", json11::Json::array { 1, 2, 3 } },
};
std::string json_str = my_json.dump();
int a = 0;
// stl data struct create json items.
std::list<int> l1 { 1, 2, 3 };
std::vector<int> l2 { 1, 2, 3 };
std::set<int> l3 { 1, 2, 3 };
std::map<std::string,std::string> m1 { {"k1", "v1" }, {"k2","v2" } };
std::string ss =json11::Json(m1).dump();
int ab = 0;
2. json 解析// 解析数据
{
conststd::string simple_test = R"( {"k1":"v1", "k2":42, "k3":["a",123,true,false,null]} )";
std::string err;
constauto json =json11::Json::parse(simple_test, err);
std::cout <<"k1: " << json["k1"].string_value() <<"\n";
std::cout <<"k3: " << json["k3"].dump() <<"\n";
for (auto &k : json["k3"].array_items() )
{
std::cout <<" - " << k.dump() <<"\n";
}
}
- json11 c++ 用法
- json11库的使用
- windows客户端开发--使用json11解析json
- c#$用法
- c#$用法
- static用法(C/C++)
- const用法(C/C++)
- C/C++__typedef用法
- C/C++:学习用法一 sizeof 用法
- [C/C++]#ifndef,#define用法
- [C/C++]#ifndef,#define用法
- [C/C++]#ifndef,#define用法
- c++/c 函数指针用法
- C/C++sort函数用法
- C/C++:rand()的用法
- C/C++/MFC时间用法
- c++/c static 用法总结
- [C/C++]#ifndef,#define用法
- ES6 -- 新的数据结构:Set和Map
- Can OGG Version 11 Be Used to Pump/Move Trails Generated from Version 9 or 10? (文档 ID 1297283.1)
- SpringMVC预处理方法参数HandlerMethodArgumentResolver类
- vivado编译综合全部通过但仿真却无法打开
- 字符串专题
- json11 c++ 用法
- rman创建备份
- 2015-12-09
- 1014. 福尔摩斯的约会 (20) PAT
- java多线程和并发面试(转)
- 一步一步编写自己的Web MVC框架——前言
- js中的原型
- 左右滑动的布局
- Android-混淆