Qt Forum

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

    Update: Forum Guidelines & Code of Conduct

    [SOLVED] QJsonobject value returns NULL

    General and Desktop
    2
    9
    2625
    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
      seethanellai last edited by

      HI

      I am getting some JSON format info from web API. It is retrieving data properly.

      @
      QJsonDocument jsonDocument = QJsonDocument::fromJson(jsonAsItem.toUtf8());
      QJsonObject jsonObject = jsonDocument.object();@

      jsonAsItem is
      @{"Id":5,"Name":"name1"}@

      but jsonobject returns NULL.

      Can any one help me with this?

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        Did you check whether the parsing returns an error ?

        Also, can you show the exact content of the json data you are getting ?

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

          Hi,

          parseerror errorstring also returns NULL.

          This is what i am getting from web API :
          @"{"Id":5,"Name":"name1"}"@

          [edit: added missing coding tags @ SGaist]

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            @
            QString testData("{"Id":5,"Name":"name1"}");
            QJsonParseError parserError;
            QJsonDocument doc = QJsonDocument::fromJson(testData.toUtf8(), &parserError);
            qDebug() << pareserError.errorString();
            qDebug() << doc.object();
            @

            parserError returns "no error occurred"
            and doc.object() returns the correct value

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

              Yes. For me too parse error coming as no error occured and jsondocument.object returns the value. Thanks :)

              1 Reply Last reply Reply Quote 0
              • SGaist
                SGaist Lifetime Qt Champion last edited by

                So you have everything working now ?

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

                  All the reading part is success. I am able to retrieve the information from jsonobject and array. Thanks for your help.

                  But having one more doubt. Now i need to call the POST web API for DB insertion. How to do that? Any idea.

                  I have below web URL (POST method):

                  http://localhost:49579/api/pdtdata/

                  I need to pass the below object as a input param to that method:

                  {
                  "barcode":"6281002505888",
                  "descr":"TestPDT",
                  "doc_type":"GR",
                  }

                  1 Reply Last reply Reply Quote 0
                  • SGaist
                    SGaist Lifetime Qt Champion last edited by

                    Using QNetworkAccessManager::post method

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

                      Done. Thanks.

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post