3 \section _intro Introduction
5 <a HREF="http://www.json.org/">JSON (JavaScript Object Notation)</a>
6 is a lightweight data-interchange format.
7 It can represents integer, real number, string, an ordered sequence of value, and
8 a collection of name/value pairs.
10 QJson is a qt-based library that maps JSON data to QVariant objects.
12 JSON arrays will be mapped to QVariantList instances, while JSON's objects will
13 be mapped to QVariantMap.
16 Converting JSON's data to QVariant instance is really simple:
18 // create a JSonDriver instance
23 // json is a QString containing the data to convert
24 QVariant result = parser.parse (json, &ok);
27 Suppose you're going to convert this JSON data:
36 "indent" : { "length" : 3, "use_space" : true }
40 The following code would convert the JSON data and parse it:
45 QVariantMap result = parser.parse (json, &ok).toMap();
47 qFatal("An error occured during parsing");
51 qDebug() << "encoding:" << result["encoding"].toString();
52 qDebug() << "plugins:";
54 foreach (QVariant plugin, result["plug-ins"].toList()) {
55 qDebug() << "\t-" << plugin.toString();
58 QVariantMap nestedMap = result["indent"].toMap();
59 qDebug() << "length:" << nestedMap["length"].toInt();
60 qDebug() << "use_space:" << nestedMap["use_space"].toBool();
73 The QJson::QObjectHelper class permits to serialize QObject instances into JSON. QJson::QObjectHelper also allows to
74 initialize a QObject using the values stored inside of a JSON object.
76 \section _build Build instructions
77 QJson build system is based on cmake. Download QJson sources, extract them, move inside the sources directory and then:
86 \section _download Get the code
87 Actually QJson code is hosted on KDE subversion repository. You can download it using a svn client:
89 svn co svn://anonsvn.kde.org/home/kde/trunk/playground/libs/qjson
92 Otherwise you can download source tarballs <a HREF="https://sourceforge.net/project/showfiles.php?group_id=244195">here</a>.
94 \author Flavio Castelli <flavio@castelli.name>