In order to realize a project of mine I started looking for a Qt library for mapping JSON data to Qt objects.
I came over a couple of solutions but none of them made me happy. So in the last weekend I wrote my own library : QJson The library is based on Qt toolkit and converts JSON data to QVariant instances. JSON arrays will be mapped to QVariantList instances, while JSON’s objects will be mapped to QVariantMap. The JSON parser is generated with Bison, while the scanner has been coded by me.
Converting JSON’s data to QVariant instance is really simple:
1 2 3 4 5
Suppose you’re going to convert this JSON data:
The following code would convert the JSON data and parse it:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
The output would be:
encoding: "UTF-8" plugins: - "python" - "c++" - "ruby" length: 3 use_space: true
Obtain the source
Actually QJson code is hosted on KDE subversion repository. You can download it using a svn client:
svn co svn://anonsvn.kde.org/home/kde/trunk/playground/libs/qjson
For more informations visit QJson site