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
  • 11,360
  • 21
  • 88
  • 132
user457015
  • 950
  • 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
  • 46,382
  • 17
  • 102
  • 175
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
  • 7,972
  • 4
  • 47
  • 62
chalup
  • 8,130
  • 3
  • 32
  • 37
  • 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,259
  • 3
  • 35
  • 49