Created
January 17, 2015 09:45
-
-
Save Tosainu/6dfb9de0e802f46bb52f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QCoreApplication> | |
#include <QJsonDocument> | |
#include <QJsonObject> | |
#include <QJsonValue> | |
#include <QString> | |
#include <QDebug> | |
class JsonValue : public QJsonValue { | |
public: | |
JsonValue(QJsonValue&& value) : QJsonValue(value) {} | |
JsonValue operator [] (const QString& key) const { | |
return toObject().value(key); | |
} | |
}; | |
class JsonObject : public QJsonObject { | |
public: | |
JsonObject(const QJsonObject&& o) : QJsonObject(o) {} | |
JsonValue operator [] (const QString& key) const { | |
return static_cast<JsonValue>(this->value(key)); | |
} | |
}; | |
int main(int argc, char *argv[]) { | |
QCoreApplication a(argc, argv); | |
JsonObject json = QJsonDocument::fromJson(QByteArray(R"( | |
{ | |
"relationship": { | |
"target": { | |
"id_str": "12148", | |
"id": 12148, | |
"screen_name": "ernie", | |
"following": false, | |
"followed_by": false | |
}, | |
"source": { | |
"can_dm": false, | |
"blocking": null, | |
"muting": null, | |
"id_str": "8649302", | |
"all_replies": null, | |
"want_retweets": null, | |
"id": 8649302, | |
"marked_spam": null, | |
"screen_name": "bert", | |
"following": false, | |
"followed_by": false, | |
"notifications_enabled": null | |
} | |
} | |
} | |
)")).object(); | |
qDebug() << json["relationship"]["source"]["screen_name"].toString(); | |
return a.exec(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment