Quickjson extraction key and value

I am trying to extract the key and value of an object in an array, but cannot find the correct getter:

 for (Value::ConstValueIterator itr = document["params"].Begin(); itr != document["params"].End(); ++itr)
{
    for (Value::MemberIterator m = itr->MemberBegin(); m != itr->.MemberEnd(); ++m) {

    }       
}

in the second loop, I want to extract the key and value from the iterator separately. how to make a booty?

+4
source share
2 answers

Suppose V is a JSON object that has an object with a key. You can get data like this.

const rapidjson::Value& V;
for (Value::ConstMemberIterator iter = V.MemberBegin(); iter != V.MemberEnd(); ++iter){
    printf("%s\t", iter->name.GetString());
    printf("%s\t", iter->value.GetString());
}
+5
source

m Member*where Member

struct Member { 
    GenericValue<Encoding, Allocator> name;     //!< name of member (must be a string)
    GenericValue<Encoding, Allocator> value;    //!< value of member.
};

Therefore, the correct key is for the key m->name.

This is very obvious from "rapidjson / document.h". I cannot check it further without a self-sufficient example ( https://stackoverflow.com/help/mcve , http://www.sscce.org/ ).

+1

Source: https://habr.com/ru/post/1542162/


All Articles