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)); }