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] JSON problem with Qt>=5.4
Qt 6.11 is out! See what's new in the release blog

[SOLVED] JSON problem with Qt>=5.4

Scheduled Pinned Locked Moved General and Desktop
5 Posts 1 Posters 2.0k Views 1 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by A Former User
    #1

    Hi,
    This code is OK with Qt5.3.2 :

    QString strReply = (QString)m_reponse->readAll();
    QJsonDocument jsonResponse = QJsonDocument::fromJson(strReply.toUtf8());
    QJsonObject jsonObject = jsonResponse.object();
    
    QJsonValue v  = jsonObject["valuedouble"];
    // or QJsonValue v  = jsonObject.take("valuedouble");
    
    double d=v.toDouble();
    

    I get a value in the double d that is not 0.
    but with Qt>= 5.4 this code doesn't runs not well, I get 0.0 in the double d although strReply is Ok.
    Has someone an idea about this problem ?

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi again,
      I think there is a problem with the method QJsonDocument::fromJson, from Qt>=5.4. when debugging I have seen that a member variable from jsonResponse,d, is =0x0 in the case of Qt 5.4 and not in the case of Qt5.3.2,as a result to the call of QJsonDocument::fromJson(strReply.toUtf8()); .

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          Perhaps the method QJsonDocument::fromJson doesn't accept anymore the JSON that I receive....

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            Sorry, I have seen that strReply wasn't OK and it runs with QT5.3.2 but not with Qt5.4.there was a missing " at the end of the JSON.so my problem is solved.

            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