-
Bug
-
Resolution: Invalid
-
P5: Not important
-
None
-
6.3.1
-
None
as a user of the JSON parser, I expect that for the number -9223372036854775809 in the file, the parser shouldn't convert it to a valid int64 value - yet that's exactly what's currently happening:
As a result, QCborValue is called with an integer type here:
https://github.com/qt/qtbase/blob/2ad23cd72d5f122f88ce95792a4323d639c27d25/src/corelib/serialization/qjsonparser.cpp#L704
Example:
#include <QJsonDocument> #include <QJsonObject> #include <QJsonValue> #include <QDebug> #include <string> void parseJsonWithLargeNumbers() { const std::string minInt64MinusOne = R"({"value": -9223372036854775809})"; QJsonDocument doc = QJsonDocument::fromJson(QByteArray::fromStdString(minInt64MinusOne)); if (doc.isNull()) { qWarning() << "Failed to parse JSON"; return; } QJsonObject obj = doc.object(); QJsonValue value = obj["value"]; // print -9223372036854775808 if (value.isDouble()) { qDebug() << value.toInteger(); } } int main() { parseJsonWithLargeNumbers(); return 0; }
- split from
-
QTBUG-28560 Number type support in QJsonValue
-
- Closed
-