<< February 13, 2020 | Home | February 15, 2020 >>

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 : ,

Export this post as PDF document  Export this post to PDF document

Social Bookmarks :  Add this post to Slashdot    Add this post to Digg    Add this post to Reddit    Add this post to Delicious    Add this post to Stumble it    Add this post to Google    Add this post to Technorati    Add this post to Bloglines    Add this post to Facebook    Add this post to Furl    Add this post to Windows Live    Add this post to Yahoo!
<< February 13, 2020 | Home | February 15, 2020 >>