当前位置:网站首页>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;
}边栏推荐
- 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
- The cloud native programming challenge ended, and Alibaba cloud launched the first white paper on application liveliness technology in the field of cloud native
- Novel website program source code that can be automatically collected
- Introduction to deep learning Ann neural network parameter optimization problem (SGD, momentum, adagrad, rmsprop, Adam)
- 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
- 电子协会 C语言 1级 34 、分段函数
- Two years ago, the United States was reluctant to sell chips, but now there are mountains of chips begging China for help
- 在所有SwiftUI版本(1.0-4.0)中原生实现Charts图表视图之思路
- What is the use of cloud redis? How to use cloud redis?
- The final week, I split
猜你喜欢
随机推荐
Introduction to spark core components
在所有SwiftUI版本(1.0-4.0)中原生实现Charts图表视图之思路
the input device is not a TTY. If you are using mintty, try prefixing the command with ‘winpty‘
Recursive Fusion and Deformable Spatiotemporal Attention for Video Compression Artifact Reduction
Solution of running crash caused by node error
Selection (023) - what are the three stages of event propagation?
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)
Master-slave replication principle of MySQL database
[FreeRTOS] FreeRTOS learning notes (7) - handwritten FreeRTOS two-way linked list / source code analysis
Transition technology from IPv4 to IPv6
手写简易版flexible.js以及源码分析
tornado项目之路由装饰器
what the fuck! If you can't grab it, write it yourself. Use code to realize a Bing Dwen Dwen. It's so beautiful ~!
Introduction to deep learning Ann neural network parameter optimization problem (SGD, momentum, adagrad, rmsprop, Adam)
Redis - detailed explanation of cache avalanche, cache penetration and cache breakdown
Two years ago, the United States was reluctant to sell chips, but now there are mountains of chips begging China for help
[FPGA tutorial case 7] design and implementation of counter based on Verilog
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
Electronic Association C language level 1 35, bank interest
[Flink] temporal semantics and watermark








