Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] QJsonValue has wrong number type?
Forum Update on Monday, May 27th 2025

[SOLVED] QJsonValue has wrong number type?

Scheduled Pinned Locked Moved General and Desktop
8 Posts 2 Posters 8.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AcerExtensa
    wrote on 21 Jan 2013, 16:06 last edited by
    #1

    Qt Doc says:
    @The QJsonValue class encapsulates a value in JSON.

    A value in JSON can be one of 6 basic types:

    JSON is a format to store structured data. It has 6 basic data types:
    bool QJsonValue::Bool
    double QJsonValue::Double
    string QJsonValue::String
    array QJsonValue::Array
    object QJsonValue::Object
    null QJsonValue::Null
    @

    Why its number type is double? What about other number types like int, long, long long etc... ?

    JSON RFC tells nothing about double!

    bq. A JSON text is a sequence of tokens. The set of tokens includes six structural characters, strings, numbers, and three literal names.

    The simple JSON text: { "id" : 13587828937364 } turns to unusable QJsonValue(double, 1.35878e+13) how should I convert it to long? simple casting doesn't work of course..

    Qt5 has so many BUG's and it is so unstable.. it just can't be called "release" version.. no way... beta, - maximum...

    God is Real unless explicitly declared as Integer.

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lgeyer
      wrote on 21 Jan 2013, 16:28 last edited by
      #2

      How would you express rational numbers when not using double (and an integer type instead), as there is just a single number type in JSON.

      In addition, this conforms with JavaScript (whose number type is also double) as far as I know.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        AcerExtensa
        wrote on 21 Jan 2013, 17:15 last edited by
        #3

        There is not just a SINGLE number type in JSON. There is nothing said about "single type" of number. Number can be int, long and double and it lays on implementator how to separate this number types.

        JavaScript is not C++, this is clear like 2+2. You can't compare number type usage implementation in JavaScript and in C/C++. It is simply different, so it needs different implementation.

        Or you want to say what parsing 13587828937364 to 1.35878e+13 is correct? It is not! And it is work in JavaScript, Java and C# JSON implementation!

        God is Real unless explicitly declared as Integer.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          AcerExtensa
          wrote on 21 Jan 2013, 17:21 last edited by
          #4

          bq. How would you express rational numbers when not using double (and an integer type instead), as there is just a single number type in JSON.

          Didn't saw you have updated your post...
          But one more time, nowhere is said you should use only one type in implementation! If it is needed(and it is needed in C/C++) you can parse number type in long type or in double! On output you will in any way parse whole types in plain text JSON structure! There is absolutely no prohibition to do what at all!

          God is Real unless explicitly declared as Integer.

          1 Reply Last reply
          0
          • L Offline
            L Offline
            lgeyer
            wrote on 21 Jan 2013, 18:16 last edited by
            #5

            If the standard allows for multiple internal storage types the implementation in Qt should definitly reflect this behaviour. -Please file a "bug report":https://bugreports.qt-project.org/.-

            There already is https://bugreports.qt-project.org/browse/QTBUG-28560

            1 Reply Last reply
            0
            • A Offline
              A Offline
              AcerExtensa
              wrote on 22 Jan 2013, 07:57 last edited by
              #6

              Yep, voted already....

              God is Real unless explicitly declared as Integer.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                AcerExtensa
                wrote on 22 Jan 2013, 16:07 last edited by
                #7

                I have looked into the QJson code and found what the separation between numbers with and without floating point is already there(in private classes), but it is not exposed and used in the QJsonValue class.

                So I have simple changed "Double" enum type to "Number"(like it actually should be) enum type, added toLongLong, isDouble functions, some other check states and now it works like it should and you can still directly use toDouble without checking if it is a double or not.

                Maybe it is a good idea to change this in Qt5 source itself?
                patch can be downloaded from here: "Qt5 JSON patch":http://vip2006.net/json.patch or from here "Qt5 JSON patch":http://xplatforms.de/json.patch

                God is Real unless explicitly declared as Integer.

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  lgeyer
                  wrote on 22 Jan 2013, 16:15 last edited by
                  #8

                  Of course it is! ;-)

                  But be aware that the QtProject does not accept any patches not provided through "Gerrit":https://codereview.qt-project.org/ (for legal reasons).

                  1 Reply Last reply
                  0

                  1/8

                  21 Jan 2013, 16:06

                  • Login

                  • Login or register to search.
                  1 out of 8
                  • First post
                    1/8
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved