Skip to content

Instantly share code, notes, and snippets.

@Tosainu
Created January 17, 2015 09:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tosainu/6dfb9de0e802f46bb52f to your computer and use it in GitHub Desktop.
Save Tosainu/6dfb9de0e802f46bb52f to your computer and use it in GitHub Desktop.
#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