当前位置:网站首页>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;
}
边栏推荐
- window上用.bat文件启动项目
- Label management of kubernetes cluster
- "Sword finger offer" 2nd Edition - force button brush question
- Vulhub vulnerability recurrence 77_ zabbix
- How to input single quotation marks and double quotation marks in latex?
- BibTex中参考文献种类
- Summary of MySQL common judgment functions!! Have you used it
- Zephyr 學習筆記2,Scheduling
- Lottery system test report
- [Chongqing Guangdong education] National Open University spring 2019 770 real estate appraisal reference questions
猜你喜欢
【森城市】GIS数据漫谈(一)
Unity 从Inspector界面打开资源管理器选择并记录文件路径
win10微软拼音输入法输入文字时候下方不出现中文提示
com. alibaba. nacos. api. exception. NacosException
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
[Valentine's day] - you can change your love and write down your lover's name
Industrial computer anti-virus
Transition technology from IPv4 to IPv6
Responsive - media query
The cloud native programming challenge ended, and Alibaba cloud launched the first white paper on application liveliness technology in the field of cloud native
随机推荐
Boosting the Performance of Video Compression Artifact Reduction with Reference Frame Proposals and
rapidjson读写json文件
uniapp小程序分包
BasicVSR++: Improving Video Super-Resolutionwith Enhanced Propagation and Alignment
The final week, I split
Responsive - media query
How can the old version of commonly used SQL be migrated to the new version?
用于压缩视频感知增强的多目标网络自适应时空融合
Basic DOS commands
[thread pool]
Zephyr 学习笔记1,threads
2022 - 021arts: début du deuxième semestre
Adaptive spatiotemporal fusion of multi-target networks for compressed video perception enhancement
The cloud native programming challenge ended, and Alibaba cloud launched the first white paper on application liveliness technology in the field of cloud native
Uniapp applet subcontracting
【FPGA教程案例7】基于verilog的计数器设计与实现
Recursive Fusion and Deformable Spatiotemporal Attention for Video Compression Artifact Reduction
[FPGA tutorial case 7] design and implementation of counter based on Verilog
Data double write consistency between redis and MySQL
NLP literature reading summary