単純な json ファイルで、この方法でオブジェクトに値を設定できます。
Qt コード:
if(file.open(QIODevice::ReadOnly)){
QJsonDocument doc = QJsonDocument::fromJson(file.readAll());
QJsonObject obj = doc.object();
obj["gender"] = "female";
doc.setObject(obj);
manager.put(request, doc.toJson());
}
シンプルな json ファイル:
{
"resourceType": "Patient",
"gender": "male",
"birthDate": "2018-08-21"
}
したがって、このコードは性別の値を女性に変更します。
しかし、「オブジェクトの下にオブジェクト」がある大きなjsonを使用すると
{
"resource": {
"resourceType": "Patient",
"id": "530f8eb0-1f0b-41b0-b94",
"text": {
"status": "generated",
"div": "<div xmlns=\"http://www.w3.org/1999/xhtml\">Teppo Testman\n <a name=\"mm\"></a>\n </div>"
},
"name": [{
"family": "Testman",
"given": [
"Teppo"
]
}],
"gender": "male",
"birthDate": "1993-02-12"
}
}
アップデート:
{
"resourceType": "Bundle",
"id": "17772d63-3b14-494f-8182-06b67c970550",
"meta": {
"versionId": "1",
"lastUpdated": "2018-08-15T12:08:48.036+00:00"
},
"type": "collection",
"entry": [{
"resource": {
"resourceType": "Observation",
"text": {
"status": "generated",
"div": "<div xmlns=\"http://www.w3.org/1999/xhtml\">Height\n <a name=\"mm\"></a>\n </div>"
},
"status": "final",
"code": {
"coding": [{
"system": "http://loinc.org",
"code": "8302-2",
"display": "Body height"
}]
},
"subject": {
"reference": "Patient/530f8eb0-1f0b-41b0-b94b-c25a14656645"
},
"valueQuantity": {
"value": 166,
"unit": "cm"
}
}
},
{
"resource": {
"resourceType": "Observation",
"text": {
"status": "generated",
"div": "<div xmlns=\"http://www.w3.org/1999/xhtml\">BMI\n <a name=\"mm\"></a>\n </div>"
},
"status": "final",
"code": {
"coding": [{
"system": "http://loinc.org",
"code": "39156-5",
"display": "Body mass index (BMI) [Ratio]"
}]
},
"subject": {
"reference": "Patient/530f8eb0-1f0b-41b0-b94b-c25a14656645"
},
"valueString": "23"
}
},
{
"resource": {
"resourceType": "Observation",
"text": {
"status": "generated",
"div": "<div xmlns=\"http://www.w3.org/1999/xhtml\">FEV1 [l]\n <a name=\"mm\"></a>\n </div>"
},
"status": "final",
"code": {
"coding": [{
"system": "http://loinc.org",
"code": "18759-1",
"display": "Spirometry study"
}]
},
"subject": {
"reference": "Patient/530f8eb0-1f0b-41b0-b94b-c25a14656645"
},
"valueQuantity": {
"value": 2,
"unit": "l"
}
}
},
{
"resource": {
"resourceType": "Observation",
"text": {
"status": "generated",
"div": "<div xmlns=\"http://www.w3.org/1999/xhtml\">FEV6 [l]\n <a name=\"mm\"></a>\n </div>"
},
"status": "final",
"code": {
"coding": [{
"system": "http://loinc.org",
"code": "18759-1",
"display": "Spirometry study"
}]
},
"subject": {
"reference": "Patient/530f8eb0-1f0b-41b0-b94b-c25a14656645"
},
"valueQuantity": {
"value": 2.9,
"unit": "l"
}
}
},
{
"resource": {
"resourceType": "Observation",
"text": {
"status": "generated",
"div": "<div xmlns=\"http://www.w3.org/1999/xhtml\">PEF [l/s]\n <a name=\"mm\"></a>\n </div>"
},
"status": "final",
"code": {
"coding": [{
"system": "http://loinc.org",
"code": "18759-1",
"display": "Spirometry study"
}]
},
"subject": {
"reference": "Patient/530f8eb0-1f0b-41b0-b94b-c25a14656645"
},
"valueQuantity": {
"value": 6.5,
"unit": "l/s"
}
}
},
{
"resource": {
"resourceType": "Patient",
"id": "530f8eb0-1f0b-41b0-b94b-c25a14656645",
"text": {
"status": "generated",
"div": "<div xmlns=\"http://www.w3.org/1999/xhtml\">Teppo Testman\n <a name=\"mm\"></a>\n </div>"
},
"name": [{
"family": "Testman",
"given": [
"Teppo"
]
}],
"gender": "male",
"birthDate": "1993-02-12"
}
}
]
}
値を変更できません。それを行う簡単な方法はありますか?私は解決策を見つけようとしましたが、成功しませんでした!