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. QNetworkAccessManager delete json
Forum Updated to NodeBB v4.3 + New Features

QNetworkAccessManager delete json

Scheduled Pinned Locked Moved Unsolved General and Desktop
11 Posts 4 Posters 644 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.
  • Q Offline
    Q Offline
    QQuickView or
    wrote on last edited by
    #1

    HI,
    I need to follow this instruction

    URL http://127.0.0.1:4578/DeleteItem
    Request DELETE
    Example
    {
    "storeId": "1588041156676",
    "list": [
    "7888",
    "1257"
    ]
    }

    How to do it?
    My code doesn't work just for delete

    QJsonDocument docJsonSent;
    QJsonObject objSent;
    QJsonArray arrayItemList

    objSent["storeId"] = QString::number(m_storeId);
    
    
    QJsonObject objElementOne,objElementTwo;
    
    objElementOne["barCode"] = "7888";
    objElementTwo["barCode"] = "1257";
    
    
    arrayItemList.append(objElementOne);
    arrayItemList.append(objElementTwo);
    
    objSent["list"] = arrayItemList;
    
    
    docJsonSent.setObject(objSent);
    
    
    QNetworkRequest request(QUrl("http://127.0.0.1:4578/DeleteItem"));
    
    request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
    QByteArray tokenByteArray;
    tokenByteArray.append(m_token);
    request.setRawHeader(QByteArray("Authorization"), tokenByteArray);
    
    
    qDebug()<<"SEND JSON:"<<docJsonSent;
    
    QByteArray data = docJsonSent.toJson();
    
    managerDeeleteCommodity->sendCustomRequest(request,"DELETE",data);
    
    jsulmJ 1 Reply Last reply
    0
    • Q QQuickView or

      HI,
      I need to follow this instruction

      URL http://127.0.0.1:4578/DeleteItem
      Request DELETE
      Example
      {
      "storeId": "1588041156676",
      "list": [
      "7888",
      "1257"
      ]
      }

      How to do it?
      My code doesn't work just for delete

      QJsonDocument docJsonSent;
      QJsonObject objSent;
      QJsonArray arrayItemList

      objSent["storeId"] = QString::number(m_storeId);
      
      
      QJsonObject objElementOne,objElementTwo;
      
      objElementOne["barCode"] = "7888";
      objElementTwo["barCode"] = "1257";
      
      
      arrayItemList.append(objElementOne);
      arrayItemList.append(objElementTwo);
      
      objSent["list"] = arrayItemList;
      
      
      docJsonSent.setObject(objSent);
      
      
      QNetworkRequest request(QUrl("http://127.0.0.1:4578/DeleteItem"));
      
      request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
      QByteArray tokenByteArray;
      tokenByteArray.append(m_token);
      request.setRawHeader(QByteArray("Authorization"), tokenByteArray);
      
      
      qDebug()<<"SEND JSON:"<<docJsonSent;
      
      QByteArray data = docJsonSent.toJson();
      
      managerDeeleteCommodity->sendCustomRequest(request,"DELETE",data);
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @QQuickView-or said in QNetworkAccessManager delete json:

      objElementOne["barCode"] = "7888";
      objElementTwo["barCode"] = "1257";

      This is different to example JSON you show. So, how exactly should it look like?
      In your example JSON the IDs are simply array elements, there is no "barCode".

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

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        QQuickView or
        wrote on last edited by QQuickView or
        #3

        Yes, you are right. thanks) But the question is, what doesn't work "delete"? post work and get work. How to delete?

        jsulmJ JonBJ 2 Replies Last reply
        0
        • Q QQuickView or

          Yes, you are right. thanks) But the question is, what doesn't work "delete"? post work and get work. How to delete?

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

          @QQuickView-or said in QNetworkAccessManager delete json:

          But the question is, what doesn't work "delete"?

          I don't know. Do you send correct JSON?

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

          Q 1 Reply Last reply
          0
          • jeremy_kJ Offline
            jeremy_kJ Offline
            jeremy_k
            wrote on last edited by
            #5

            Does "doesn't work" mean

            • the code doesn't compile
            • the request is never transmitted
            • the transmitted request is malformatted
            • the program terminates abnormally
            • something else?

            Asking a question about code? http://eel.is/iso-c++/testcase/

            1 Reply Last reply
            1
            • Q Offline
              Q Offline
              QQuickView or
              wrote on last edited by
              #6

              JSON parse error: Cannot deserialize instance of java.lang.String

              Everything works through " postman.co "

              jsulmJ 1 Reply Last reply
              0
              • Q QQuickView or

                JSON parse error: Cannot deserialize instance of java.lang.String

                Everything works through " postman.co "

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

                @QQuickView-or said in QNetworkAccessManager delete json:

                JSON parse error: Cannot deserialize instance of java.lang.String

                Sounds like your JSON is invalid...

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

                1 Reply Last reply
                1
                • Q QQuickView or

                  Yes, you are right. thanks) But the question is, what doesn't work "delete"? post work and get work. How to delete?

                  JonBJ Online
                  JonBJ Online
                  JonB
                  wrote on last edited by JonB
                  #8

                  @QQuickView-or said in QNetworkAccessManager delete json:

                  Yes, you are right. thanks) But the question is, what doesn't work "delete"?

                  As @jsulm has pointed out to you, your code does not produce what you show in Example (even if you use "list" in place of "barCode"). You already know this from your qDebug() line. So what do you expect if what you send does not match what you show as being required?

                  1 Reply Last reply
                  0
                  • jsulmJ jsulm

                    @QQuickView-or said in QNetworkAccessManager delete json:

                    But the question is, what doesn't work "delete"?

                    I don't know. Do you send correct JSON?

                    Q Offline
                    Q Offline
                    QQuickView or
                    wrote on last edited by QQuickView or
                    #9

                    @jsulm qDebug QJsonDocument({"list":[{"":"7888"},{"":"1257"}],"storeId":"1588041156676"})

                    jsulmJ JonBJ 2 Replies Last reply
                    0
                    • Q QQuickView or

                      @jsulm qDebug QJsonDocument({"list":[{"":"7888"},{"":"1257"}],"storeId":"1588041156676"})

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

                      @QQuickView-or I doubt this:

                      "list":[{"":"7888"},{"":"1257"}]
                      

                      is what is expected. Shouldn't it be

                      "list":[7888, 1257]
                      

                      ?
                      You should really read JSON you generate and think about it correctness...

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

                      1 Reply Last reply
                      2
                      • Q QQuickView or

                        @jsulm qDebug QJsonDocument({"list":[{"":"7888"},{"":"1257"}],"storeId":"1588041156676"})

                        JonBJ Online
                        JonBJ Online
                        JonB
                        wrote on last edited by
                        #11

                        @QQuickView-or
                        As @jsulm says.

                        Start by forgetting about your QJson... code. Just create a hard-coded QString for the payload, based on what your server wants, till you get that working. That rules out JSON problems. Then change over to correctly generating the desired string with QJson... calls.

                        1 Reply Last reply
                        1

                        • Login

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