diff --git a/src/parser/parser_abstract.cpp b/src/parser/parser_abstract.cpp index 33d07d74..72d9eca6 100644 --- a/src/parser/parser_abstract.cpp +++ b/src/parser/parser_abstract.cpp @@ -145,11 +145,11 @@ void ParserAbstract::sendHttpRequest(QUrl url, QByteArray data, const QListevaluate("(" + utf8 + ")").toVariant().toMap(); + doc = engine->evaluate("(" + utf8 + ")").toVariant(); delete engine; #endif @@ -168,9 +168,9 @@ QVariantMap ParserAbstract::parseJson(const QByteArray &json) const } #ifdef BUILD_FOR_QT5 -QByteArray ParserAbstract::serializeToJson(const QVariantMap& doc) const +QByteArray ParserAbstract::serializeToJson(const QVariant& doc) const { - return QJsonDocument(QJsonObject::fromVariantMap(doc)).toJson(QJsonDocument::Indented); + return QJsonDocument::fromVariant(doc).toJson(QJsonDocument::Indented); } #else QByteArray toJson(const QVariant& value) @@ -212,7 +212,7 @@ QByteArray toJson(const QVariant& value) } } -QByteArray ParserAbstract::serializeToJson(const QVariantMap& doc) const +QByteArray ParserAbstract::serializeToJson(const QVariant& doc) const { return toJson(doc); } diff --git a/src/parser/parser_abstract.h b/src/parser/parser_abstract.h index c31823ec..665ed766 100644 --- a/src/parser/parser_abstract.h +++ b/src/parser/parser_abstract.h @@ -92,8 +92,8 @@ protected slots: virtual void parseJourneyDetails(QNetworkReply *networkReply); void sendHttpRequest(QUrl url, QByteArray data, const QList > &additionalHeaders = QList >()); void sendHttpRequest(QUrl url); - QVariantMap parseJson(const QByteArray &data) const; - QByteArray serializeToJson(const QVariantMap &doc) const; + QVariant parseJson(const QByteArray &data) const; + QByteArray serializeToJson(const QVariant &doc) const; QByteArray gzipDecompress(QByteArray compressData); #ifdef BUILD_FOR_UBUNTU diff --git a/src/parser/parser_finland_matka.cpp b/src/parser/parser_finland_matka.cpp index 92372f9c..fdeba713 100644 --- a/src/parser/parser_finland_matka.cpp +++ b/src/parser/parser_finland_matka.cpp @@ -147,7 +147,7 @@ void ParserFinlandMatka::parseStationsByName(QNetworkReply *networkReply) } // qDebug() << "Reply:\n" << allData; - QVariantMap doc = parseJson(allData); + QVariantMap doc = parseJson(allData).toMap(); if (doc.isEmpty()) { emit errorOccured(tr("Cannot parse reply from the server")); return; @@ -299,7 +299,7 @@ void ParserFinlandMatka::parseTimeTable(QNetworkReply *networkReply) } // qDebug() << "Reply:\n" << allData; - QVariantMap doc = parseJson(allData); + QVariantMap doc = parseJson(allData).toMap(); if (doc.isEmpty()) { emit errorOccured(tr("Cannot parse reply from the server")); return; @@ -664,7 +664,7 @@ void ParserFinlandMatka::parseSearchJourney(QNetworkReply *networkReply) } // qDebug() << "Reply:\n" << allData; - QVariantMap doc = parseJson(allData); + QVariantMap doc = parseJson(allData).toMap(); if (doc.isEmpty()) { emit errorOccured(tr("Cannot parse reply from the server")); return; diff --git a/src/parser/parser_ninetwo.cpp b/src/parser/parser_ninetwo.cpp index 1dab8be3..b01db398 100644 --- a/src/parser/parser_ninetwo.cpp +++ b/src/parser/parser_ninetwo.cpp @@ -209,7 +209,7 @@ void ParserNinetwo::parseTimeTable(QNetworkReply *networkReply) QByteArray allData = networkReply->readAll(); // qDebug() << "REPLY:>>>>>>>>>>>>\n" << allData; - QVariantMap doc = parseJson(allData); + QVariantMap doc = parseJson(allData).toMap(); if (doc.isEmpty()) { emit errorOccured(tr("Cannot parse reply from the server")); return; @@ -287,7 +287,7 @@ void ParserNinetwo::parseStationsByName(QNetworkReply *networkReply) QByteArray allData = networkReply->readAll(); // qDebug() << "REPLY:>>>>>>>>>>>>\n" << allData; - QVariantMap doc = parseJson(allData); + QVariantMap doc = parseJson(allData).toMap(); if (doc.isEmpty()) { emit errorOccured(tr("Cannot parse reply from the server")); return; @@ -346,7 +346,7 @@ void ParserNinetwo::parseSearchJourney(QNetworkReply *networkReply) QByteArray allData = networkReply->readAll(); qDebug() << "REPLY:>>>>>>>>>>>>\n" << allData; - QVariantMap doc = parseJson(allData); + QVariantMap doc = parseJson(allData).toMap(); if (doc.isEmpty()) { emit errorOccured(tr("Cannot parse reply from the server")); return; diff --git a/src/parser/parser_resrobot.cpp b/src/parser/parser_resrobot.cpp index af323ec5..16800320 100644 --- a/src/parser/parser_resrobot.cpp +++ b/src/parser/parser_resrobot.cpp @@ -376,17 +376,17 @@ void ParserResRobot::parseTimeTable(QNetworkReply *networkReply) QByteArray allData = networkReply->readAll(); // qDebug() << "Reply:\n" << allData; - QVariantMap doc = parseJson(allData); - if (doc.isEmpty()) { + QVariant reply = parseJson(allData); + if (!reply.isValid()) { emit errorOccured(tr("Cannot parse reply from the server")); return; } - + QVariantMap replyMap = reply.toMap(); QVariantList departures; if (timetableSearchMode == Arrival) - departures = doc.value("Arrival").toList(); + departures = replyMap.value("Arrival").toList(); else - departures = doc.value("Departure").toList(); + departures = replyMap.value("Departure").toList(); TimetableEntriesList timetable; foreach (QVariant departureData, departures) { TimetableEntry resultItem; @@ -439,12 +439,13 @@ void ParserResRobot::parseStationsByName(QNetworkReply *networkReply) QByteArray allData = networkReply->readAll(); // qDebug() << "Reply:\n" << allData; - QVariantMap doc = parseJson(allData); - if (doc.isEmpty()) { + QVariant reply = parseJson(allData); + if (!reply.isValid()) { emit errorOccured(tr("Cannot parse reply from the server")); return; } - QVariantList stations = doc.value("StopLocation").toList(); + QVariantMap replyMap = reply.toMap(); + QVariantList stations = replyMap.value("StopLocation").toList(); StationsList result; foreach (QVariant stationData, stations) { const QVariantMap& station = stationData.toMap(); @@ -464,13 +465,13 @@ void ParserResRobot::parseStationsByCoordinates(QNetworkReply *networkReply) QByteArray allData = networkReply->readAll(); // qDebug() << "Reply:\n" << allData; - QVariantMap doc = parseJson(allData); - if (doc.isEmpty()) { + QVariant reply = parseJson(allData); + if (!reply.isValid()) { emit errorOccured(tr("Cannot parse reply from the server")); return; } - - QVariantList stations = doc.value("StopLocation").toList(); + QVariantMap replyMap = reply.toMap(); + QVariantList stations = replyMap.value("StopLocation").toList(); StationsList result; foreach (QVariant stationData, stations) { const QVariantMap& station = stationData.toMap(); @@ -490,15 +491,15 @@ void ParserResRobot::parseSearchJourney(QNetworkReply *networkReply) QByteArray allData = networkReply->readAll(); // qDebug() << "Reply:\n" << allData; - QVariantMap doc = parseJson(allData); - if (doc.isEmpty()) { + QVariant reply = parseJson(allData); + if (!reply.isValid()) { emit errorOccured(tr("Cannot parse reply from the server")); return; } - - searchEarlierReference = doc.value("scrB").toString(); - searchLaterReference = doc.value("scrF").toString(); - QVariantList journeyListData = doc.value("Trip").toList(); + QVariantMap replyMap = reply.toMap(); + searchEarlierReference = replyMap.value("scrB").toString(); + searchLaterReference = replyMap.value("scrF").toString(); + QVariantList journeyListData = replyMap.value("Trip").toList(); cachedResults.clear();