c++rapidjson

rapidjson SetString - GetString


I try setting a Value to string, using SetString, but when I try to get it, via GetString(), some random output shows up. Code:

someDoc[someObjKey].AddMember(someStringKey.c_str(), someStringValueAFunctionReturns.c_str(), someDoc.GetAllocator());
std::cout << someDoc[someObjKey][someStringKey.c_str()].GetString();

What am I doing wrong?


Solution

  • OK, after browsing trough the source code, documentation and mostly every mention of rapidjson over the internet, I found something interesting:

    There are a couple of functions SetString, and this is the one you have to use:

    GenericValue& SetString(const Ch* s, Allocator& allocator)
    

    After that, you can call GetString()on the Valueand it returns the original string.