Looping over an array in RapidJson and getting the object elements

Jonny picture Jonny · Aug 31, 2015 · Viewed 6.9k times · Source

How do I get the value out of a ConstrValueIterator? In this case I know that the elements of the array are dictionaries (aka objects).

Code summed up:

for (rapidjson::Value::ConstValueIterator itr = rawbuttons.Begin(); itr != rawbuttons.End(); ++itr) { // Ok
    if (itr->HasMember("yes")) { // Ok
        auto somestring = itr["yes"]->GetString(); // error
    }
}

Answer

Jonny picture Jonny · Aug 31, 2015

Um. Iterators need to be dereferenced or whatever it's called.

for (rapidjson::Value::ConstValueIterator itr = rawbuttons.Begin(); itr != rawbuttons.End(); ++itr) { // Ok
    if (itr->HasMember("yes")) { // Ok
        auto somestring = (*itr)["yes"]->GetString(); // bingo
    }
}