我需要解析一个文件,获取一些数据并使用 RapidJson 将它们写入另一个文件。
现在我可以检索值并将它们放入文档中。我唯一的问题是将该文档插入文件中:
FILE * pFile = fopen ("read.json" , "r");
FILE * wFile = fopen ("Test.json" , "w");
if (pFile != NULL)
{
rapidjson::FileStream is(pFile);
rapidjson::Document document;
document.ParseStream<0>(is);
string mMeshID = a.GetString();
//how to add that document to wfile
fclose (pFile);
}
有什么方法可以在文件中编写 RapidJson::Document 吗?
编辑:我发现的唯一方法是:
// Convert JSON document to string
GenericStringBuffer< UTF8<> > buffer;
Writer<GenericStringBuffer< UTF8<> > > writer(buffer);
doc.Accept(writer);
const char* str = buffer.GetString();
fprintf(wFile, "%s", str);
fclose(wFile);