Details
-
Suggestion
-
Resolution: Done
-
P3: Somewhat important
-
None
-
5.0.0 RC 1, 5.0.0 RC 2, 5.0.0, 5.9.0
-
Any
-
edec095cf80b62057116ce75c581b5ca5866bdcc (qt/qtbase/dev)
Description
We've recently ported one of our projects from JsonCpp to an early version of the QtJson implementation. The migration went smoothly for the most part, but there is a glaring difference in the APIs – QtJson doesn't support integral types.
This is a problem for us, as we would like to be able to store 64-bit unsigned integers in some of our JSON snippets (we use JSON to store state about remote systems that use uint64 identifiers). QJsonValue only supports doubles, and in the JSON strings these are truncated via QByteArray::number to %.6g, so the values cannot be represented accurately, e.g. quint64's maximum value is only represented as 1.84467e+19 instead of 18446744073709551615.
This is an enormous loss of precision. Was there a reason for not supporting these types? Are there plans to extend QJsonValue to support integers (preferably before 5.0)?
Simple test which shows the problem:
#include <QCoreApplication> #include <QJsonDocument> #include <QJsonObject> #include <QDateTime> #include <QDebug> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QDateTime stamp = QDateTime::currentDateTime(); QString jStr = "{\"id\":"+QString::number(stamp.toTime_t())+"}"; QJsonDocument jDoc = QJsonDocument::fromJson(jStr.toLatin1()); qDebug() << jDoc.object().value("id"); qDebug() << "original time stamp: " << stamp.toString("MM dd yyyy hh:mm:ss z"); qDebug() << "time stamp from json: " << QDateTime::fromTime_t(jDoc.object().value("id").toDouble()).toString("MM dd yyyy hh:mm:ss z"); qDebug() << "JSON returns same value? " << (stamp == QDateTime::fromTime_t(jDoc.object().value("id").toDouble())); return 0; }
Attachments
Issue Links
- relates to
-
QTBUG-42419 QJsonDocument::toJson() generates extra large text.
- Closed
For Gerrit Dashboard: QTBUG-28560 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
195241,4 | Add an abstract "number" to JSON | dev | qt/qtbase | Status: ABANDONED | 0 | 0 |
277622,8 | Fix 64-bit integer support in QtJSON | dev | qt/qtbase | Status: MERGED | +2 | 0 |