diff --git a/apiresponse.cpp b/apiresponse.cpp index cddb7bb..bfa5986 100644 --- a/apiresponse.cpp +++ b/apiresponse.cpp @@ -1,3 +1,5 @@ +#include + #include "apiresponse.h" APIResponse::APIResponse(int code, QByteArray content) : @@ -16,7 +18,14 @@ QByteArray APIResponse::getContent() const return mContent; } + + bool APIResponse::isError() { return mCode != 200; } + +QJsonObject APIResponse::getObject() const +{ + return QJsonDocument::fromJson(mContent).object(); +} diff --git a/apiresponse.h b/apiresponse.h index 7a332ed..0e9d7c1 100644 --- a/apiresponse.h +++ b/apiresponse.h @@ -5,6 +5,7 @@ */ #include +#include #pragma once @@ -19,6 +20,8 @@ public: bool isError(); + QJsonObject getObject() const; + private: int mCode; QByteArray mContent; diff --git a/loginwindow.cpp b/loginwindow.cpp index 30337c3..b67e087 100644 --- a/loginwindow.cpp +++ b/loginwindow.cpp @@ -83,7 +83,8 @@ void LoginWindow::onResponse(APIResponse res) return; } - QMessageBox::information(this, "ok", "success"); + auto token = res.getObject().value("tokens").toObject().value("token1").toString(); + QMessageBox::information(this, "ok", token); } void LoginWindow::on_submitButton_clicked()