当前位置:网站首页>rapidjson读写json文件
rapidjson读写json文件
2022-07-04 07:13:00 【面向对象】
#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;
}
边栏推荐
- 校园网络问题
- 图的底部问题
- 在已经知道表格列勾选一个显示一列
- Two years ago, the United States was reluctant to sell chips, but now there are mountains of chips begging China for help
- Electronic Association C language level 1 35, bank interest
- Boosting the Performance of Video Compression Artifact Reduction with Reference Frame Proposals and
- How to share the source code anti disclosure scheme
- 高薪程序员&面试题精讲系列119之Redis如何实现分布式锁?
- Uniapp applet subcontracting
- Selection (022) - what is the output of the following code?
猜你喜欢
[Android reverse] function interception (use cache_flush system function to refresh CPU cache | refresh CPU cache disadvantages | recommended time for function interception)
[thread pool]
A real penetration test
Introduction to deep learning Ann neural network parameter optimization problem (SGD, momentum, adagrad, rmsprop, Adam)
【森城市】GIS数据漫谈(一)
Industrial computer anti-virus
Two years ago, the United States was reluctant to sell chips, but now there are mountains of chips begging China for help
《剑指Offer》第2版——力扣刷题
Splicing plain text into JSON strings - easy language method
How to share the source code anti disclosure scheme
随机推荐
[Valentine's day] - you can change your love and write down your lover's name
NLP-文献阅读总结
Research on an endogenous data security interaction protocol oriented to dual platform and dual chain architecture
Zabbix agent主动模式的实现
How to share the source code anti disclosure scheme
Lottery system test report
Master-slave replication principle of MySQL database
[Mori city] random talk on GIS data (I)
About how idea sets up shortcut key sets
校园网络问题
what the fuck! If you can't grab it, write it yourself. Use code to realize a Bing Dwen Dwen. It's so beautiful ~!
大厂技术专家:架构设计中常用的思维模型
电子协会 C语言 1级 35 、银行利息
Recursive Fusion and Deformable Spatiotemporal Attention for Video Compression Artifact Reduction
Electronic Association C language level 1 34, piecewise function
selenium IDE插件下载安装使用教程
uniapp小程序分包
How does the recv of TCP socket receive messages of specified length?
MySQL 45 lecture learning notes (XIII) delete half of the table data, and the table file size remains the same
MySQL 45 lecture learning notes (XIV) count (*)