easiest way to parse JSON in Qt 4.7 easiest way to parse JSON in Qt 4.7 json json

easiest way to parse JSON in Qt 4.7


JSON parsing is now supported in Qt 5. Here's how to load and parse a document:

#include <QByteArray>#include <QFile>#include <QJsonObject>#include <QJsonDocument>// ...// Read JSON fileQFile file("/path/to/file.json");file.open(QIODevice::ReadOnly);QByteArray rawData = file.readAll();// Parse documentQJsonDocument doc(QJsonDocument::fromJson(rawData));// Get JSON objectQJsonObject json = doc.object();// Access propertiesqDebug() << json["something"].toString();


Try QJson.

QJson is actively developed (and used by KDE, if I'm not mistaken). The best is to checkout the source code directly and built it yourself. There is no dependencies to QJson (except for Qt and CMake). It's pretty simple to use too, have a look at some usage examples :

http://qjson.sourceforge.net/usage/


If you don't want to depend on external libraries you could use the QScriptEngine

http://qtwiki.remdex.info/Parsing_JSON_with_QT_using_standard_QT_library