Precision of QJson parser/integer limits
I have a problem regarding the precision of the QJsonParser. A few days ago, I was able to solve the task of parsing a json from a file in general (with help of the forum in this thread:http://qt-project.org/forums/viewthread/52980/).
Now, I noticed that some conversions during the parsing process do not have the required precision. For example, a 64-bit integer from the file, such as "73847942565529089", is stored as the QJsonValue "73847942565529088". The integer "73847942566053377" results in "73847942566053376". There are more similar cases, where the last digit is not correct. How can I ensure a correct conversion/parsing for such values?
It seems that the integer limits for IEEE 754 double precision data are the problem here. Is there any way to bypass this problem (to get the "original" string during the parsing, etc.)?
You're right, the issue stems from the original JSON specification which represents all numbers as double-precision floating point numbers (or at least, it was originally interpreted this way). There's currently no way to parse 64-bit integers using QJson, but there's a "recent discussion":http://comments.gmane.org/gmane.comp.lib.qt.devel/20202 among Qt engineers on how to work around this.
In the meantime, you could store your numbers as strings, and then manually convert them to integers.
Thank you for the information! In the meantime, I could bypass the problem by splitting the related values into blocks of 32bits each (within the json).