addmember put a unicode string instead of std::string into json.
while reading the json, where i used hard coded std::string (e.g. "myKey") its fine. but when i use a string value from a variable (e.g. rapidjson::StringRef( myKeyStr.c_str()) ) it saves unicode value of string like "\u0000\u0000\u0000\234\254\234{\216\206"
i am using rapidjson in cocos2d-x 3.12 in xcode 7.3
here is code and output screenshot
https://www.dropbox.com/sh/njshhc4u9896mpc/AAA3b19-DBf3RgPqDaQgmQkDa?dl=0
Using StringRef assumes the pointer has a safe life cycle. But std::string::c_str()does not.
Use copy-string instead:
o.AddMember("key", Value(myKeyStr.c_str(), allocator).Move(), allocator);
Most helpful comment
Using
StringRefassumes the pointer has a safe life cycle. Butstd::string::c_str()does not.Use copy-string instead: