Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [SOLVED] JSON problem with Qt>=5.4

    General and Desktop
    1
    5
    780
    Loading More Posts
    • 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.
    • S
      stephane78 last edited by stephane78

      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 Reply Quote 0
      • S
        stephane78 last edited by

        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 Reply Quote 0
        • S
          stephane78 last edited by

          This post is deleted!
          1 Reply Last reply Reply Quote 0
          • S
            stephane78 last edited by

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

            1 Reply Last reply Reply Quote 0
            • S
              stephane78 last edited by

              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 Reply Quote 0
              • First post
                Last post