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] QJsonobject value returns NULL
QtWS25 Last Chance

[SOLVED] QJsonobject value returns NULL

Scheduled Pinned Locked Moved General and Desktop
9 Posts 2 Posters 3.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.
  • S Offline
    S Offline
    seethanellai
    wrote on last edited by
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      0
      • S Offline
        S Offline
        seethanellai
        wrote on last edited by
        #3

        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
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @
          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
          0
          • S Offline
            S Offline
            seethanellai
            wrote on last edited by
            #5

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

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

              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
              0
              • S Offline
                S Offline
                seethanellai
                wrote on last edited by
                #7

                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
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  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
                  0
                  • S Offline
                    S Offline
                    seethanellai
                    wrote on last edited by
                    #9

                    Done. Thanks.

                    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