Skip to content

Instantly share code, notes, and snippets.

@Tosainu
Last active August 29, 2015 14:13
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/c451e277912cc7e605f7 to your computer and use it in GitHub Desktop.
Save Tosainu/c451e277912cc7e605f7 to your computer and use it in GitHub Desktop.
QtでJson
#include <QCoreApplication>
#include <QJsonDocument>
#include <QJsonObject>
#include <QDebug>
int main(int argc, char *argv[]) {
QCoreApplication a(argc, argv);
auto 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
}
}
}
)"));
// "relationship" => "source" => "screen_name" の文字列が取りたい
// 理想
// qDebug() << json["relationship"]["source"]["screen_name"].toString();
// 現実
qDebug() << json.object().value("relationship").toObject().value("source").toObject().value("screen_name").toString();
return a.exec();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment