c++ Json库读取和写入json文件

#include "json\include\writer.h"
#include "json\include\reader.h"
#include <fstream>

bool ModifyJsonConfigFileByPath(const std::string &path)
{
Json::Reader reader;
Json::Value root;
std::string file = path + "/config/config.json";
std::ifstream in(file,std::ios_base::binary); //以二进制方式读进
if (!in)
{
return false;
}

bool bret = reader.parse(in, root);
if (!bret || root.isNull())
{
return false;
}
in.close();

root["data_path"] = path + "/data/";
root["model_path"] = path + "/data/model/";
root["license_folder"] = path + "/license/";
root["verification_config"] = "config/verification.json";// path + "/data/config/verification.json";
root["savefolder"] = path + "/faceverify_log";


std::ofstream out(file,std::ios_base::binary);
if (!out)
{
return false;
}
Json::StyledStreamWriter writer;
writer.write(out, root);
out.close();
return true;
}

猜你喜欢

转载自blog.csdn.net/qqwangfan/article/details/77943500