需求
nlohmman
读写 json
配置文件.
解决
写文件
QString fileName = QFileDialog::getSaveFileName(this, tr("save config file"), "./voltage_", tr("Json (*.json)"));
qDebug() << fileName << Qt::endl;
if (fileName.isEmpty())
return;
ofstream file(fileName.toStdString(), ios::out);
json j;
to_json(j, config_json);
file << j << std::endl;
读文件
QString file_name = QFileDialog::getOpenFileName(this, tr("load config file"), "./voltage_", tr("Json (*.json)"));
qDebug() << file_name << Qt::endl;
if (file_name.isEmpty())
return;
ifstream file(file_name.toStdString(), ios::in);
json j = json::parse(file);