nlohmann json:通过[ ]运算符读取设置object/array

除了可以通过at,还可以通过[ ]运算符来读取和设置object/array

#include 
#include 
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<

运行程序输出:

"xiaoming"
40
{"age":10,"name":"xiaoming","parent":

你可能感兴趣的:(C/C++,json)