如何在文件中添加Rapidjson ::文档
How to add rapidjson::Document in file
我需要解析文件,获取一些数据并使用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);
}
有什么方法可以在文件中写下rappjson ::文档?
编辑:我发现的唯一方法是:
// 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);
提出了有关FileWriteStream
的更好文档。
使用FileWriteStream
代替StringBuffer
可以减少内存使用量。FileWriteStream
使用固定大小的缓冲区(可以存储在堆栈中),而StringBuffer
则需要将整个JSON存储在(HEAP)内存中。对于Big Json而言,这是一个很大的区别。
您最好使用
fwrite (buffer.GetString(), buffer.GetSize(), 1, wFile);
它更安全(如果缓冲区未终止终止),并且更快(没有strlen)。
除此之外,并且缺少错误检查您的代码,它很好,应该写入文件np。
相关文章:
- 正在查找文档以获得PS4平台的C++中的设备信息
- 如何在文档文件夹中创建目录
- 当Microsoft文档仅包含 C# 示例时,如何查找 C++ 包含文件名
- 通过构造函数创建一些值并尝试添加到文档中使用 rapidjson 不起作用
- 关于类的 Python 文档 - 对C++的引用不正确
- C++/autoconf 等效于文档库要求.txt的要求是什么?
- 如何使用基于范围的for循环迭代Rapidjson文档(它本身就是一个JSON数组)
- RapidJSON 文档创建嵌套对象
- 从 Rapidjson 值转换为 Rapidjson 文档
- Rapidjson将密钥值从一个文档对象分配到另一个文档对象
- rapidjson:如何将文档对象拆分为较小的文档对象
- 如何在文件中添加Rapidjson ::文档
- 在使用 RapidJSON 解析文档时跳过某些字段
- RapidJSON:使用文档或编写器构建之间的差异
- 如何将字符串对添加到rapidjson的文档中
- rapidjson:用于从文件中读取文档的工作代码
- 如何将RapidJSON文档序列化为字符串
- Rapidjson:在文档中添加外部子文档
- 比较rapidjson:文档
- Rapidjson返回对文档值的引用