-
Notifications
You must be signed in to change notification settings - Fork 1
/
apiresponse.cpp
36 lines (32 loc) · 1.06 KB
/
apiresponse.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "Apiresponse.h"
ApiResponse::ApiResponse(const QByteArray &responseData){
QJsonDocument jsonDoc = QJsonDocument::fromJson(responseData);
if (jsonDoc.isObject()) {
QJsonObject jsonObject = jsonDoc.object();
processJsonObject(jsonObject);
} else {
qDebug() << "Invalid JSON format";
}
}
bool ApiResponse::isSuccess()
{
if(code==200||code==201)
return true;
else return false;
}
void ApiResponse::processJsonObject(const QJsonObject &jsonObject)
{
if (jsonObject.contains("code")) {
qDebug() << "Value for code:" << jsonObject.value("code").toInt();
code=jsonObject.value("code").toInt();
}
if (jsonObject.contains("message")) {
qDebug() << "Value for message:" << jsonObject.value("message").toString();
message=jsonObject.value("message").toString();
}
if (jsonObject.contains("data")) {
qDebug() << "Value for data:" << jsonObject.value("data").toObject();
data=jsonObject.value("data").toObject();
datav=jsonObject.value("data");
}
}