读取及设置:
#include <iostream>
#include <nlohmann/json.hpp>
using namespace std;
using json = nlohmann::json;int main()
{json data = R"({"name": "xiaoming","age": 10, "parent": [{"father" : "zhang","age" : 40},{"mother" : "wang","age" : 36}]})"_json;cout<<data.at("name")<<endl;cout<<data.at("parent").at(0).at("age")<<endl;data.at("parent").at(0).at("age") = 42;cout<<data<<endl;return 0;
}
运行程序输出:
"xiaoming"
40
{"age":10,"name&