I am parsing a JSON
structure which is similar as follows
{
\"item1\" : \"value1\"
\"item2\" : \"value2\"
// ...
\"itemn\" : {
void parseRecursive(std::string scope
, rapidjson::Value::ConstMemberIterator object
, std::unordered_map& values)
{
if (scope.empty())
{
scope = object->name.GetString();
}
else
{
scope = scope + "::" + object->name.GetString();
}
auto inElement = scope + "::";
if (object->value.IsObject())
{
for (auto it = object->value.MemberBegin(); it != object->value.MemberEnd(); ++it)
{
parseRecursive(scope, it, values);
}
}
else if (object->value.IsDouble())
{
values.emplace(inElement, std::to_string(object->value.GetDouble()));
}
else if (object->value.IsInt())
{
values.emplace(inElement, std::to_string(object->value.GetInt()));
}
else
{
LOGW("Unsuported: " << inElement << object->name.GetString());
}
}
And start with document: rapidjson::Document document;
for (auto it = document.MemberBegin(); it != document.MemberEnd(); ++it)
{
parseRecursive("", it, _values);
}