14

How can I JSON serialize a QVariant (or other type of data) in Qt. I don't want to use an external third party library like QJson

tshepang
  • 12,111
  • 21
  • 91
  • 136
user457015
  • 960
  • 4
  • 14
  • 33

3 Answers3

22

Just to mention, as of Qt5, JSON is officially supported:

JSON Support in Qt

QVariant id(1), name("John Doe");
QJsonObject json;

json["Name"] = name.toString();
json.insert("id", id.toInt());
dtech
  • 47,916
  • 17
  • 112
  • 190
5

Parsing JSON with QT using standard QT library.

BTW: why don't you want to use QJson? It nicely encapsulates all the QScriptValueIterator stuff, making your code easier to read.

Honest Abe
  • 8,430
  • 4
  • 49
  • 64
chalup
  • 8,358
  • 3
  • 33
  • 38
  • 1
    @BojanKogoj It still exists here: https://web.archive.org/web/20130111091817/http://qtwiki.remdex.info/Parsing_JSON_with_QT_using_standard_QT_library – kol May 22 '15 at 14:58
-6

There are no internal tools in Qt to do it. You will have to use a lib. Or roll your own implementation

ak.
  • 3,329
  • 3
  • 38
  • 50