QNetworkAccessManager delete json
-
HI,
I need to follow this instructionURL 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 deleteQJsonDocument docJsonSent;
QJsonObject objSent;
QJsonArray arrayItemListobjSent["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); -
HI,
I need to follow this instructionURL 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 deleteQJsonDocument docJsonSent;
QJsonObject objSent;
QJsonArray arrayItemListobjSent["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);@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". -
Yes, you are right. thanks) But the question is, what doesn't work "delete"? post work and get work. How to delete?
-
Yes, you are right. thanks) But the question is, what doesn't work "delete"? post work and get work. How to delete?
@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?
-
JSON parse error: Cannot deserialize instance of
java.lang.StringEverything works through " postman.co "
-
JSON parse error: Cannot deserialize instance of
java.lang.StringEverything works through " postman.co "
@QQuickView-or said in QNetworkAccessManager delete json:
JSON parse error: Cannot deserialize instance of java.lang.String
Sounds like your JSON is invalid...
-
Yes, you are right. thanks) But the question is, what doesn't work "delete"? post work and get work. How to delete?
@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 yourqDebug()line. So what do you expect if what you send does not match what you show as being required? -
@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?
@jsulm qDebug QJsonDocument({"list":[{"":"7888"},{"":"1257"}],"storeId":"1588041156676"})
-
@jsulm qDebug QJsonDocument({"list":[{"":"7888"},{"":"1257"}],"storeId":"1588041156676"})
@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... -
@jsulm qDebug QJsonDocument({"list":[{"":"7888"},{"":"1257"}],"storeId":"1588041156676"})
@QQuickView-or
As @jsulm says.Start by forgetting about your
QJson...code. Just create a hard-codedQStringfor 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 withQJson...calls.