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. Strange Json issue, conversion from QByteArray to QJsonDocument not working as intended
Forum Updated to NodeBB v4.3 + New Features

Strange Json issue, conversion from QByteArray to QJsonDocument not working as intended

Scheduled Pinned Locked Moved Solved General and Desktop
jsonqtcreatorinstallationbytearray
16 Posts 5 Posters 6.4k Views 4 Watching
  • 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.
  • D DanBar

    I have a strange issue working with Json...

    I receive an encrypted byte array from a network source, the length varies but currently under testing it is an array of either about 100 characters or a bit over 20 000 characters. I output the recieved byte array (after decryption) and the resulting json document to a log file to keep track (see in the code below)

    When I run a debug in Qt Creator (version 4.5.1, Based on Qt 5.10.1 (MSVC 2015, 32 bit)) everything works fine, but when I build an installation file and install it I get this really weird issue. The short array (about 100 characters) still works as it should, but the long one doesn't. The output in the log file of the "tmpTestJson" is just empty. I can see that all characters are received, but for some reason the conversion to Json document isn't working.

    Can a Json character array be too long? Why do I get an issue in the installed version but not in the debug version? Any help is appreciated.

    This is the code where i have the issue:

    QByteArray configData = reply->readAll();
    AESCryptoUtil aes;
    QByteArray decryptedConfigData = aes.Decrypt(QByteArray::fromBase64(configData));
    emit log(QString("received data: " + decryptedConfigData));
    
    QJsonDocument configJsonDoc = QJsonDocument::fromJson(decryptedConfigData);
    QString tmpTestJson = configJsonDoc.toJson(QJsonDocument::Indented);
    log(QString("Json Document: " + tmpTestJson));
    
    raven-worxR Offline
    raven-worxR Offline
    raven-worx
    Moderators
    wrote on last edited by
    #2

    @DanBar said in Strange Json issue, conversion from QByteArray to QJsonDocument not working as intended:

    QByteArray configData = reply->readAll();

    are you 100% sure that at the time you call reply->readAll() you really have received all data (=valid JSON data)?!

    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
    If you have a question please use the forum so others can benefit from the solution in the future

    D 1 Reply Last reply
    4
    • raven-worxR raven-worx

      @DanBar said in Strange Json issue, conversion from QByteArray to QJsonDocument not working as intended:

      QByteArray configData = reply->readAll();

      are you 100% sure that at the time you call reply->readAll() you really have received all data (=valid JSON data)?!

      D Offline
      D Offline
      DanBar
      wrote on last edited by
      #3

      @raven-worx I get the entire bytearray (including the finishing brackets) when "decryptedConfigData" is printed, but nothing when "tmpTestJson". As far as I know that means that I get all the data and should have valid Json data. The printed "decryptedConfigData" is identical when running in the debugger and the installed version.

      raven-worxR 1 Reply Last reply
      0
      • D DanBar

        @raven-worx I get the entire bytearray (including the finishing brackets) when "decryptedConfigData" is printed, but nothing when "tmpTestJson". As far as I know that means that I get all the data and should have valid Json data. The printed "decryptedConfigData" is identical when running in the debugger and the installed version.

        raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #4

        @DanBar
        What is the output of the following?

        QJsonParseError jsonError;
        QJsonDocument configJsonDoc = QJsonDocument::fromJson(decryptedConfigData, &jsonError);
        if( jsonError.error != QJsonParseError::NoError )
             log( QString("Json error: %1").arg(jsonError.errorString()) );
        else if( configJsonDoc .isNull() )
             log( "Null JsonDocument );
        

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        D 1 Reply Last reply
        3
        • raven-worxR raven-worx

          @DanBar
          What is the output of the following?

          QJsonParseError jsonError;
          QJsonDocument configJsonDoc = QJsonDocument::fromJson(decryptedConfigData, &jsonError);
          if( jsonError.error != QJsonParseError::NoError )
               log( QString("Json error: %1").arg(jsonError.errorString()) );
          else if( configJsonDoc .isNull() )
               log( "Null JsonDocument );
          
          D Offline
          D Offline
          DanBar
          wrote on last edited by
          #5

          @raven-worx I get the following:

          "Json error: illegal number"

          what does that mean?

          jsulmJ raven-worxR 2 Replies Last reply
          0
          • D DanBar

            @raven-worx I get the following:

            "Json error: illegal number"

            what does that mean?

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by jsulm
            #6

            @DanBar Can you show the JSON string you get?

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • D DanBar

              @raven-worx I get the following:

              "Json error: illegal number"

              what does that mean?

              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by raven-worx
              #7

              @DanBar said in Strange Json issue, conversion from QByteArray to QJsonDocument not working as intended:

              "Json error: illegal number"
              what does that mean?

              possibly an integer/decimal value beginning with 0 (e.g. propertyName: 01234)? unless it's an octal value.

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              D 1 Reply Last reply
              0
              • raven-worxR raven-worx

                @DanBar said in Strange Json issue, conversion from QByteArray to QJsonDocument not working as intended:

                "Json error: illegal number"
                what does that mean?

                possibly an integer/decimal value beginning with 0 (e.g. propertyName: 01234)? unless it's an octal value.

                D Offline
                D Offline
                DanBar
                wrote on last edited by
                #8

                @raven-worx There are many values that are 0 and a few values that are decimal, are those allowed while running in Qtcreator but not as an installed program?

                a sample part of the json:
                "name": "Test 4",
                "valueA": 180,
                "valueB": "",
                "valueC": 9,
                "valueD": 1,
                "valueE": 0.8869204367,
                "valueF": 1500,
                "valueG": "C",
                "valueH": 0,
                "valueI": "16d29c44-3d0941",
                "valueJ": "1392fa45-68c943",
                "valueK": "2018-08-06 09:07:29",

                mrjjM raven-worxR 2 Replies Last reply
                0
                • D DanBar

                  @raven-worx There are many values that are 0 and a few values that are decimal, are those allowed while running in Qtcreator but not as an installed program?

                  a sample part of the json:
                  "name": "Test 4",
                  "valueA": 180,
                  "valueB": "",
                  "valueC": 9,
                  "valueD": 1,
                  "valueE": 0.8869204367,
                  "valueF": 1500,
                  "valueG": "C",
                  "valueH": 0,
                  "valueI": "16d29c44-3d0941",
                  "valueJ": "1392fa45-68c943",
                  "valueK": "2018-08-06 09:07:29",

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #9

                  @DanBar
                  Hi
                  You you also output
                  http://doc.qt.io/qt-5/qjsonparseerror.html#offset-var
                  as it gives a clue where in the file it gets error.

                  1 Reply Last reply
                  0
                  • D DanBar

                    @raven-worx There are many values that are 0 and a few values that are decimal, are those allowed while running in Qtcreator but not as an installed program?

                    a sample part of the json:
                    "name": "Test 4",
                    "valueA": 180,
                    "valueB": "",
                    "valueC": 9,
                    "valueD": 1,
                    "valueE": 0.8869204367,
                    "valueF": 1500,
                    "valueG": "C",
                    "valueH": 0,
                    "valueI": "16d29c44-3d0941",
                    "valueJ": "1392fa45-68c943",
                    "valueK": "2018-08-06 09:07:29",

                    raven-worxR Offline
                    raven-worxR Offline
                    raven-worx
                    Moderators
                    wrote on last edited by raven-worx
                    #10

                    @DanBar said in Strange Json issue, conversion from QByteArray to QJsonDocument not working as intended:

                    There are many values that are 0 and a few values that are decimal, are those allowed while running in Qtcreator but not as an installed program?
                    a sample part of the json:
                    "name": "Test 4",
                    "valueA": 180,
                    "valueB": "",
                    "valueC": 9,
                    "valueD": 1,
                    "valueE": 0.8869204367,
                    "valueF": 1500,
                    "valueG": "C",
                    "valueH": 0,
                    "valueI": "16d29c44-3d0941",
                    "valueJ": "1392fa45-68c943",
                    "valueK": "2018-08-06 09:07:29",

                    none of those values should raise this error as far i see.
                    I was talking about decimals bigger than 0. So 0 is of course a valid decimal value, but 02934 not

                    But you havent answered my first question. Are you sure you already received the full data before you start to parse the JSON data?!

                    --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                    If you have a question please use the forum so others can benefit from the solution in the future

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #11

                      Hi,

                      How long is the long array that makes things fail ?

                      See QTBUG-47629 for a limitation on QJsonObject's size.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • D Offline
                        D Offline
                        DanBar
                        wrote on last edited by
                        #12

                        Thank you all for your help!

                        I was able to solve this issue, but the problem wasn't in the Json itself. I got a tip a tip from my colleague to check the .dll-files in the installation folder, and I noticed that they weren't entirely up to date. When I replaced them with the correct version of .dll-files the issue was solved. I still don't know exactly what caused this issue between the versions (version 5.9 and 5.10) but the issue is solved so I'm happy in either case.

                        Again, thanks!

                        jsulmJ 1 Reply Last reply
                        1
                        • D DanBar

                          Thank you all for your help!

                          I was able to solve this issue, but the problem wasn't in the Json itself. I got a tip a tip from my colleague to check the .dll-files in the installation folder, and I noticed that they weren't entirely up to date. When I replaced them with the correct version of .dll-files the issue was solved. I still don't know exactly what caused this issue between the versions (version 5.9 and 5.10) but the issue is solved so I'm happy in either case.

                          Again, thanks!

                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by
                          #13

                          @DanBar said in Strange Json issue, conversion from QByteArray to QJsonDocument not working as intended:

                          installation folder

                          Which installation folder do you mean? Qt? Your app?

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          D 1 Reply Last reply
                          0
                          • jsulmJ jsulm

                            @DanBar said in Strange Json issue, conversion from QByteArray to QJsonDocument not working as intended:

                            installation folder

                            Which installation folder do you mean? Qt? Your app?

                            D Offline
                            D Offline
                            DanBar
                            wrote on last edited by
                            #14

                            @jsulm Not the Qt folder, my own installation folder for the software I'm creating.

                            jsulmJ 1 Reply Last reply
                            0
                            • D DanBar

                              @jsulm Not the Qt folder, my own installation folder for the software I'm creating.

                              jsulmJ Offline
                              jsulmJ Offline
                              jsulm
                              Lifetime Qt Champion
                              wrote on last edited by
                              #15

                              @DanBar How do you create this installation directory? Qt provides tools for deployment.

                              https://forum.qt.io/topic/113070/qt-code-of-conduct

                              D 1 Reply Last reply
                              0
                              • jsulmJ jsulm

                                @DanBar How do you create this installation directory? Qt provides tools for deployment.

                                D Offline
                                D Offline
                                DanBar
                                wrote on last edited by
                                #16

                                @jsulm we make an installation file for our combined system, including multiple programs sharing some but not other resources. we use an nsi script to manage this. usually works fine. I just missed updating some of the .dll files.

                                1 Reply Last reply
                                0

                                • Login

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