Reputation: 11
My code is like this:
rapidjson::Document doc;
doc.SetObject();
// insert some sub JsonObjects
rapidjson::Document subA;
if (!subA.Parse<0>(jsonStringA->c_str()).HasParseError()) {
doc.AddMember("A", subA, doc.GetAllocator());
}
rapidjson::Document subB;
if (!subB.Parse<0>(jsonStringB->c_str()).HasParseError()) {
doc.AddMember("B", subB, doc.GetAllocator());
}
// Export document as string
rapidjson::StringBuffer buf;
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buf);
doc.Accept(writer);
buffer.GetString();
Fatal signal 6 (SIGABRT) produced after called buffer.GetString();
And the abort message is:
/document.h:1778: bool rapidjson::GenericValue<rapidjson::UTF8<char>, rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator> >::Accept(Handler &) const [Encoding = rapidjson::UTF8<char>, Allocator = rapidjson::MemoryPoolAllocator<rapidjson::CrtAllocator>, Handler = rapidjson::PrettyWriter<rapidjson::GenericStringBuffer<rapidjson::UTF8<char>, rapidjson::CrtAllocator>, rapidjson::UTF8<char>, rapidjson::UTF8<char>, rapidjson::CrtAllocator, 0>]: assertion "m->name.IsString()" failed'
I don't know what is wrong with my code.
And if i replace "rapidjson::Document subA
" with "rapidjson::Document subA(doc.GetAllocator())
",
this issue appears to be resolved. But i don't know why.
Upvotes: 1
Views: 130