Tencent / rapidjson

A fast JSON parser/generator for C++ with both SAX/DOM style API
http://rapidjson.org/
Other
14.17k stars 3.52k forks source link

Nested array does not get written using Writer #1629

Open andre-ferreira opened 4 years ago

andre-ferreira commented 4 years ago

Hello,

I am having trouble writing nested arrays back into the file. Rapidjson correctly reads the nested arrays but when trying to write it back to a file (even without any changes) the inner arrays do not get copied.

I use the following for writing to file:

//Convert it back to a string
rapidjson::StringBuffer str_buffer(0, 2048);
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(str_buffer);
s_LoadedDocument.Accept(writer);
std::string json(str_buffer.GetString(), str_buffer.GetSize());

// Write to file
std::ofstream out(s_documentPath);
out << json;
out.close();

This is what i am expecting to see in the json: ... "animConfig": [[3, 3, 3, 3, 1, 0, 1, 1, 2]], ...

and this is what i get: "animConfig": [[]],

This happens to all nested arrays in the json, not just to this one.

What am i doing wrong?

Many thanks

andre-ferreira commented 4 years ago

The issue is the following line in another part of the code:

const rapidjson::Value& rp_array = rpd_value->GetArray();

Linked to issue #1436