How to serialize to JSON in Qt

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


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());

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.

See this JSON Save Game example on serialization of an object to a JSON document.

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

Need Your Help

Way to check whether TinyMCE is active in WordPress

javascript wordpress tinymce

I'm working on a plugin that, when TinyMCE is in use as the Visual editor, uses TinyMCE commands to insert text into body content editing area. Currently, it works by just running the command. If it

What is IMEX within OLEDB connection strings?

c# connection-string oledb

"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=localhost;Extended Properties=""Excel 8.0;HDR=Yes;IMEX=2"