void addJson(string number,string streampath,string site, string resolutionratio, string refreshrate) {
//1. 将磁盘文件中的json字符串读到磁盘文件
ifstream ifs("test1.json");
//2. 反序列化 -> value对象
Value root;
Reader r;
r.parse(ifs, root);
//3. 从value对象中将数据依次读出
//创建并初始化子对象
Value subObj;
Value obj;
// 添加键值对
subObj["streampath"] = streampath;
subObj["site"] = site;
subObj["resolutionratio"] = resolutionratio;
subObj["refreshrate"] = refreshrate;
root[0][number] = Value(subObj);
ofstream ofs;
ofs.open("test1.json");
//ofs.clear();
ofs << root.toStyledString();
ofs.close();
cout << root.toStyledString() << endl;
}
jsoncpp实现“增”功能
最新推荐文章于 2024-08-18 17:42:33 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)