Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.3.2, 5.4.0 RC
-
Mac OS X 10.9.5
-
4b63ab9a93, 3e5152be41
Description
Json "value:null" is converted to invalid QVariant when calling QJsonObject::toVariantMap(). When that variantmap is stringified in QML then null valued property is vanished. Can be reproduced by attached example.
Expected output is:
qml: {"x":null,"y":10}
and output is:
qml: {"y":10}
Workaround is to replace invalid values with null QJsonValue:
QString json = "{\"x\":null, \"y\": 10}"; QJsonDocument jsonDoc = QJsonDocument::fromJson(json.toLatin1()); QVariantMap map = jsonDoc.object().toVariantMap(); // WORKAROUND: foreach(QString k, map.keys()) { QVariant v = map.value(k); if(!v.isValid()) map.insert(k,QJsonValue(QJsonValue::Null)); }
Attachments
For Gerrit Dashboard: QTBUG-43077 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
126187,4 | QJsonValue::toVariant(): Differentiate between null and invalid | dev | qt/qtbase | Status: MERGED | +2 | 0 |