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
Asked
Active
Viewed 1.7k times
14
-
Related → http://stackoverflow.com/questions/15893040/how-to-create-read-write-json-files-in-qt5 – Honest Abe Aug 23 '15 at 03:25
3 Answers
22
Just to mention, as of Qt5, JSON is officially supported:
QVariant id(1), name("John Doe");
QJsonObject json;
json["Name"] = name.toString();
json.insert("id", id.toInt());

dtech
- 47,916
- 17
- 112
- 190
-
-
https://stackoverflow.com/questions/28181627/how-to-convert-a-qjsonobject-to-qstring – Ashif Aug 30 '20 at 05:36
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
-
2nowadays is this answer no longer valid, there is a QJsonObject class – ΦXocę 웃 Пepeúpa ツ Oct 05 '18 at 08:13