Looping over an array in RapidJson and getting the object elements

拥有回忆 提交于 2019-12-22 06:05:17

问题


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
    }
}

回答1:


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
    }
}



回答2:


It should be

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


来源:https://stackoverflow.com/questions/32303257/looping-over-an-array-in-rapidjson-and-getting-the-object-elements

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!