diff options
Diffstat (limited to 'src/corelib/serialization/qjsonvalue.cpp')
-rw-r--r-- | src/corelib/serialization/qjsonvalue.cpp | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/corelib/serialization/qjsonvalue.cpp b/src/corelib/serialization/qjsonvalue.cpp index 27a2f0e227..0b11907e68 100644 --- a/src/corelib/serialization/qjsonvalue.cpp +++ b/src/corelib/serialization/qjsonvalue.cpp @@ -449,11 +449,8 @@ void QJsonValue::swap(QJsonValue &other) noexcept also affects this function. A floating point value that is either an infinity or NaN will be converted - to a null JSON value. Since Qt 6.0, QJsonValue can store the full precision - of any 64-bit signed integer without loss, but in previous versions values - outside the range of ±2^53 may lose precision. Unsigned 64-bit values - greater than or equal to 2^63 will either lose precision or alias to - negative values, so QMetaType::ULongLong should be avoided. + to a null JSON value. The values outside the range of ±2^53 may lose precision, + because they are converted to a double QJsonValue. For other types not listed above, a conversion to string will be attempted, usually but not always by calling QVariant::toString(). If the conversion @@ -708,10 +705,13 @@ QString QJsonValue::toString() const */ QJsonArray QJsonValue::toArray(const QJsonArray &defaultValue) const { - if (t != QCborValue::Array || n >= 0 || !d) + if (!isArray()) return defaultValue; - - return QJsonArray(d.data()); + QCborContainerPrivate *dd = nullptr; + Q_ASSERT(n == -1 || d == nullptr); + if (n < 0) + dd = d.data(); + return QJsonArray(dd); } /*! @@ -733,10 +733,13 @@ QJsonArray QJsonValue::toArray() const */ QJsonObject QJsonValue::toObject(const QJsonObject &defaultValue) const { - if (t != QCborValue::Map || n >= 0 || !d) + if (!isObject()) return defaultValue; - - return QJsonObject(d.data()); + QCborContainerPrivate *dd = nullptr; + Q_ASSERT(n == -1 || d == nullptr); + if (n < 0) + dd = d.data(); + return QJsonObject(dd); } /*! |