C++解析json时,使用nlohmann json工具解析方便快捷。把它记录下来,方便以后查阅。
//地址:https://github.com/nlohmann/json, 需要引用的头文件位置:single_include/nlohmann/json.hpp
//需要引用的头文件,在使用时,将这个文件加入到工程中即可,只添加这一个文件就行
//#include "json.hpp"
//using nlohmann::json;
//创建普通元素和子元素
/*{
"answer":{"everything":42},
"happy":true,
"list":[0,1,2],
"name":"Mike",
"nothing":null,
"object":{
"currency":"USD",
"value":23
},
"pi":3.14
}*/
//
json j;
j["pi"] = 3.14;
j["happy"] = true;
j["name"] = "Mike";
j["nothing"] = nullptr;
j["answer"]["everything"] = 42;
j["list"] = {0, 1, 2};
j["object"] = {
{"currency", "USD"}, {"value", 23}};
cout<

订阅专栏 解锁全文

8104

被折叠的 条评论
为什么被折叠?



