2

I use rapid json to serialize a dict, the key is uint32 and the value is a long string. The code is:

rapidjson::StringBuffer buffer();                                                                                                                                     
rapidjson::Write<< rapidjson::StringBuffer>> writer(buffer);  
root.Accept(writer);  
const char* json_str = buffer.GetString();

But, I found the final json_str is truncated. Does any one known how to avoid truncation?

Darren Shewry
  • 10,179
  • 4
  • 50
  • 46

1 Answers1

1

If assume that the truncation has place due to zero character inside your long string then you can avoid it by stop using char * and use std::string instead.

rapidjson::StringBuffer buffer();                                                                                                                                     
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);  
root.Accept(writer);  
std::string json_str = std::string(buffer.GetString(), buffer.GetSize());
user2807083
  • 2,962
  • 4
  • 29
  • 37