<< GGJ '20 : Preparations | Home | Multimonitor-Setup mit 4k and HD >>

rapidjson: iterate over object and array

    // get an object    
    auto groups = doc["groups"].GetObject();

    // iterate over key-value-pairs ( group.name and group.value )
    for (auto const& group : groups){
        cout << "group:" << group.name.GetString() << endl;

        // the value is an array. The call to iterate over the array is basically the same as for the object 
        for (auto const& p : group.value.GetArray()){
            cout << "\t" << p.GetString() << endl;
        }
    }

obviously you don't need to const the value:

for (auto& group : groups){...
Tags : ,
Home