当前位置:网站首页>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;
}
边栏推荐
- Electronic Association C language level 1 35, bank interest
- If there are two sources in the same job, it will be reported that one of the databases cannot be found. Is there a boss to answer
- SQL foundation 9 [grouping data]
- 2022-021ARTS:下半年開始
- NLP literature reading summary
- 用于压缩视频感知增强的多目标网络自适应时空融合
- The cloud native programming challenge ended, and Alibaba cloud launched the first white paper on application liveliness technology in the field of cloud native
- What is the use of cloud redis? How to use cloud redis?
- JS common time processing functions
- How to buy financial products in 2022?
猜你喜欢
Introduction to deep learning Ann neural network parameter optimization problem (SGD, momentum, adagrad, rmsprop, Adam)
[web security] nodejs prototype chain pollution analysis
响应式移动Web测试题
Implementation of ZABBIX agent active mode
uniapp小程序分包
大厂技术专家:架构设计中常用的思维模型
提升复杂场景三维重建精度 | 基于PaddleSeg分割无人机遥感影像
Boosting the Performance of Video Compression Artifact Reduction with Reference Frame Proposals and
Zabbix agent主动模式的实现
Review of enterprise security incidents: how can enterprises do a good job in preventing source code leakage?
随机推荐
js 常用时间处理函数
How to buy financial products in 2022?
Zephyr 学习笔记2,Scheduling
Adaptive spatiotemporal fusion of multi-target networks for compressed video perception enhancement
[Mori city] random talk on GIS data (I)
Novel website program source code that can be automatically collected
Zephyr Learning note 2, Scheduling
Su Weijie, a member of Qingyuan Association and an assistant professor at the University of Pennsylvania, won the first Siam Youth Award for data science, focusing on privacy data protection, etc
Flink memory model, network buffer, memory tuning, troubleshooting
A real penetration test
响应式移动Web测试题
Bottom problem of figure
Status of the thread
The number of patent applications in China has again surpassed that of the United States and Japan, ranking first in the world for 11 consecutive years
Cell reports: Wei Fuwen group of the Institute of zoology, Chinese Academy of Sciences analyzes the function of seasonal changes in the intestinal flora of giant pandas
Selection (023) - what are the three stages of event propagation?
the input device is not a TTY. If you are using mintty, try prefixing the command with ‘winpty‘
Introduction to rce in attack and defense world
2022-021ARTS:下半年开始
Recursive Fusion and Deformable Spatiotemporal Attention for Video Compression Artifact Reduction