Commit 624c6f9ee2232cd159c65214e382278453ca480d
Exists in
master
Merge remote-tracking branch 'origin/master'
Showing
3 changed files
with
14 additions
and
5 deletions
Show diff stats
cacic-teste/testcacic.cpp
... | ... | @@ -108,10 +108,10 @@ void CTestCacic::testJsonValueFromJsonString() |
108 | 108 | |
109 | 109 | void CTestCacic::testLogin(){ |
110 | 110 | QJsonObject jsonReply = OCacicComm.login(); |
111 | -// QJsonValue sessionvalue = OCacic.jsonValueFromJsonString(json["reply"].toString(), "session"); | |
112 | 111 | QJsonValue sessionvalue = jsonReply["reply"]; |
112 | +// qDebug() << sessionvalue.toObject()["session"].toString(); | |
113 | 113 | // qDebug() << sessionvalue.toString(); |
114 | - QVERIFY(!sessionvalue.isNull()); | |
114 | + QVERIFY(sessionvalue.isObject()); | |
115 | 115 | } |
116 | 116 | |
117 | 117 | void CTestCacic::testSslConnection() | ... | ... |
src/cacic_comm.h
... | ... | @@ -99,8 +99,12 @@ public: |
99 | 99 | |
100 | 100 | if (reply->error() == QNetworkReply::NoError) { |
101 | 101 | //se não houver erro, grava o retorno; |
102 | - strReply = (QString)reply->readAll(); | |
103 | - jsonObj["reply"] = strReply; | |
102 | + QVariant replyVariant = reply->readAll(); | |
103 | + QJsonDocument replyDocument = QJsonDocument::fromJson(replyVariant.toByteArray()); | |
104 | + jsonObj["reply"] = (!replyDocument.isNull()) ? | |
105 | + replyDocument.object() : | |
106 | + QJsonValue::fromVariant(replyVariant.toString()); | |
107 | +// qDebug() << "Response:" << jsonObj["reply"]; | |
104 | 108 | // qDebug() << "Response:" << strReply; |
105 | 109 | |
106 | 110 | delete reply; | ... | ... |
src/ccacic.cpp
... | ... | @@ -102,7 +102,12 @@ bool CCacic::deleteFile(QString path) |
102 | 102 | else |
103 | 103 | return true; |
104 | 104 | } |
105 | - | |
105 | +/*jsonValueFromJsonString | |
106 | + * Pega valor da chave desejada em um json em string; | |
107 | + * @parameter QString json: json onde será feita a busca; | |
108 | + * @parameter QString key: chave onde será pego o json; | |
109 | + * @return QJsonValue: valor solicitado; | |
110 | + */ | |
106 | 111 | QJsonValue CCacic::jsonValueFromJsonString(QString json, QString key) |
107 | 112 | { |
108 | 113 | return QJsonDocument::fromJson(json.toUtf8()).object()[key]; | ... | ... |