Rapidjson: AddMember(StringRefType name, StringRefType value, Allocator& allocator) returns unicode values instead of string

Created on 15 Sep 2016  Â·  2Comments  Â·  Source: Tencent/rapidjson

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

Uploading Screen Shot 2016-09-15 at 12.59.52 PM.png…

Answered Questions

Most helpful comment

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);

All 2 comments

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);
Was this page helpful?
0 / 5 - 0 ratings