当前位置:网站首页>Rapidjson reading and writing JSON files
Rapidjson reading and writing JSON files
2022-07-04 07:18:00 【object-oriented】
#include "rapidjson/document.h"
#include "rapidjson/istreamwrapper.h"
#include "rapidjson/prettywriter.h"
#include "rapidjson/rapidjson.h"
#include "rapidjson/stringbuffer.h"
#include "rapidjson/writer.h"
#include "rapidjson/filewritestream.h"
using namespace std;
using namespace rapidjson;
string readJsonfile(string path)
{
ifstream config_file(path);
if (!config_file.is_open())
{
return "json file not exist";
}
IStreamWrapper config(config_file);
Document doc;
doc.ParseStream(config);
StringBuffer buffer;
Writer<StringBuffer> writer(buffer);
doc.Accept(writer);
config_file.close();
return buffer.GetString();
}
void writeToJsonFile(string &jsonstr, string filepath)
{
Document doc;
doc.Parse(jsonstr.c_str());
FILE* fp = fopen(filepath.c_str(), "wb");
char writeBuffer[65535];
FileWriteStream os(fp, writeBuffer, sizeof(writeBuffer));
PrettyWriter<FileWriteStream> writer(os);
doc.Accept(writer);
fclose(fp);
std::cout << "writeToJsonFile end" <<std::endl;
}
边栏推荐
- BasicVSR++: Improving Video Super-Resolutionwith Enhanced Propagation and Alignment
- 2022 - 021arts: début du deuxième semestre
- 《剑指Offer》第2版——力扣刷题
- A real penetration test
- 【FPGA教程案例7】基于verilog的计数器设计与实现
- Label management of kubernetes cluster
- Highly paid programmers & interview questions: how does redis of series 119 realize distributed locks?
- There is no Chinese prompt below when inputting text in win10 Microsoft Pinyin input method
- 提升复杂场景三维重建精度 | 基于PaddleSeg分割无人机遥感影像
- BasicVSR++: Improving Video Super-Resolutionwith Enhanced Propagation and Alignment
猜你喜欢
【GF(q)+LDPC】基于二值图GF(q)域的规则LDPC编译码设计与matlab仿真
[GF (q) + LDPC] regular LDPC coding and decoding design and MATLAB simulation based on the GF (q) field of binary graph
The IP bound to the socket is inaddr_ The meaning of any htonl (inaddr_any) (0.0.0.0 all addresses, uncertain addresses, arbitrary addresses)
socket inet_ pton() inet_ Ntop() function (a new network address translation function, which converts the expression format and numerical format to each other. The old ones are inet_aton(), INET_ ntoa
Solution of running crash caused by node error
Introduction to spark core components
leetcode825. Age appropriate friends
Summary of MySQL common judgment functions!! Have you used it
Rhcsa day 3
Vulhub vulnerability recurrence 76_ XXL-JOB
随机推荐
What is industrial computer encryption and how to do it
两年前美国芯片扭捏着不卖芯片,如今芯片堆积如山祈求中国帮忙
A new understanding of how to encrypt industrial computers: host reinforcement application
The important role of host reinforcement concept in medical industry
notepad++如何统计单词数量
Valentine's Day is coming! Without 50W bride price, my girlfriend was forcibly dragged away...
Since DMS is upgraded to a new version, my previous SQL is in the old version of DMS. In this case, how can I retrieve my previous SQL?
How to input single quotation marks and double quotation marks in latex?
The cloud native programming challenge ended, and Alibaba cloud launched the first white paper on application liveliness technology in the field of cloud native
[network data transmission] FPGA based development of 100M / Gigabit UDP packet sending and receiving system, PC to FPGA
tornado之目录
Selection (022) - what is the output of the following code?
jdbc连接es查询的时候,有遇到下面这种情况的大神嘛?
Centos8 install mysql 7 unable to start up
"Sword finger offer" 2nd Edition - force button brush question
Zephyr Learning note 2, Scheduling
JS common time processing functions
Unity 从Inspector界面打开资源管理器选择并记录文件路径
Recursive Fusion and Deformable Spatiotemporal Attention for Video Compression Artifact Reduction
Blue Bridge Cup Quick sort (code completion)