{ "paramQiVec": [ { "errorPtAndTypeLabel": [ { "errorPt": "-270.041260,1261.462524,123.234344", "errorType": 4, "label_id": "{ebf4661f-9b4e-47d3-af33-a9ed44dd42d2}" }, { "errorPt": "-247.991013,1251.029663,134.500015", "errorType": 1, "label_id": "{d6150742-c8d1-4180-852d-4d061e9e4811}" } ], "error_face": 13, "exceed_face": 0, "faceMi": [ 0.26909488439559937, 0.09684661030769348 ], } ], "qualityTime": "0分36秒", "rangeLineAir": 3378.730405988889 }我想修改label_id这个字段的值请问怎么用qt修改
时间: 2024-02-14 09:10:17 浏览: 89
要修改 "label_id" 字段的值,可以使用以下代码:
```cpp
QFile file("example.json");
file.open(QIODevice::ReadOnly | QIODevice::Text);
QJsonDocument doc = QJsonDocument::fromJson(file.readAll());
file.close();
QJsonObject obj = doc.object();
QJsonArray paramQiVec = obj["paramQiVec"].toArray();
for (int i = 0; i < paramQiVec.size(); ++i) {
QJsonObject paramQi = paramQiVec[i].toObject();
QJsonArray errorPtAndTypeLabel = paramQi["errorPtAndTypeLabel"].toArray();
for (int j = 0; j < errorPtAndTypeLabel.size(); ++j) {
QJsonObject errorPtAndType = errorPtAndTypeLabel[j].toObject();
if (errorPtAndType["label_id"].toString() == "{ebf4661f-9b4e-47d3-af33-a9ed44dd42d2}") {
errorPtAndType["label_id"] = "{new_label_id}";
errorPtAndTypeLabel[j] = errorPtAndType;
}
}
paramQi["errorPtAndTypeLabel"] = errorPtAndTypeLabel;
paramQiVec[i] = paramQi;
}
obj["paramQiVec"] = paramQiVec;
file.open(QIODevice::WriteOnly | QIODevice::Text);
file.write(doc.toJson());
file.close();
```
上述代码会将 "label_id" 值为 "{ebf4661f-9b4e-47d3-af33-a9ed44dd42d2}" 的对象的 "label_id" 字段修改为 "{new_label_id}",然后保存回 JSON 文件。需要替换成具体的值。
阅读全文