Skip to content
This repository has been archived by the owner on Mar 17, 2019. It is now read-only.

Commit

Permalink
Change to use Qt-Json (https://github.com/ereilin/qt-json) to parse JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
dicksonleong committed Apr 29, 2013
1 parent 35eadf7 commit 6b0a617
Show file tree
Hide file tree
Showing 20 changed files with 21 additions and 6,449 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
@@ -0,0 +1,3 @@
[submodule "qt-json"]
path = qt-json
url = git://github.com/ereilin/qt-json.git
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -26,5 +26,5 @@ License

GagBook is licensed under the Simplified BSD License, see the file "LICENSE" for more info.

GagBook use a backported version of JSON library from Qt 5 (in src/json/), which is licensed under the
[GNU LGPL 2.1](http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html).
GagBook use the [Qt-Json library](https://github.com/ereilin/qt-json), which is also licensed
under the Simplified BSD License, see the file "qt-json/LICENSE" for more info.
6 changes: 3 additions & 3 deletions gagbook.pro
Expand Up @@ -6,9 +6,9 @@ DEFINES += APP_VERSION=\\\"$$VERSION\\\"

QT += network webkit

# Backported JSON lib from Qt 5
# TODO: Update the JSON source from the lastest Qt release!
include(src/json/json.pri)
# Qt-Json
HEADERS += qt-json/json.h
SOURCES += qt-json/json.cpp

HEADERS += \
src/qmlutils.h \
Expand Down
1 change: 1 addition & 0 deletions qt-json
Submodule qt-json added at cca462
27 changes: 12 additions & 15 deletions src/infinigagrequest.cpp
Expand Up @@ -28,9 +28,7 @@
#include "infinigagrequest.h"

#include <QtCore/QUrl>
#include "json/qjsondocument.h"
#include "json/qjsonobject.h"
#include "json/qjsonarray.h"
#include <qt-json/json.h>

InfiniGagRequest::InfiniGagRequest(Section section, QNetworkAccessManager *manager, QObject *parent) :
GagRequest(section, manager, parent)
Expand All @@ -51,23 +49,22 @@ QList<GagObject> InfiniGagRequest::parseResponse(const QByteArray &response, con
{
Q_UNUSED(section)

QJsonParseError parseError;
const QJsonDocument jsonDocument = QJsonDocument::fromJson(response, &parseError);
bool ok;
const QVariantList results = QtJson::parse(QString::fromUtf8(response), ok).toMap().value("data").toList();

Q_ASSERT_X(parseError.error == QJsonParseError::NoError, Q_FUNC_INFO, "Error parsing JSON");

const QJsonArray gagJsonArray = jsonDocument.object().value("data").toArray();
Q_ASSERT_X(ok, Q_FUNC_INFO, "Error parsing JSON");
Q_ASSERT_X(!results.isEmpty(), Q_FUNC_INFO, "Error parsing JSON or JSON is empty");

QList<GagObject> gagList;
foreach (const QJsonValue &gagJsonValue, gagJsonArray) {
const QJsonObject gagJsonObject = gagJsonValue.toObject();
foreach (const QVariant &gagJson, results) {
const QVariantMap gagJsonMap = gagJson.toMap();

GagObject gag;
gag.setId(gagJsonObject.value("id").toString());
gag.setUrl(gagJsonObject.value("link").toString());
gag.setTitle(gagJsonObject.value("caption").toString());
gag.setImageUrl(gagJsonObject.value("images").toObject().value("normal").toString());
gag.setVotesCount(gagJsonObject.value("votes").toObject().value("count").toDouble());
gag.setId(gagJsonMap.value("id").toString());
gag.setUrl(gagJsonMap.value("link").toString());
gag.setTitle(gagJsonMap.value("caption").toString());
gag.setImageUrl(gagJsonMap.value("images").toMap().value("normal").toString());
gag.setVotesCount(gagJsonMap.value("votes").toMap().value("count").toInt());

gagList.append(gag);
}
Expand Down
17 changes: 0 additions & 17 deletions src/json/json.pri

This file was deleted.

0 comments on commit 6b0a617

Please sign in to comment.