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
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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());
回答2:
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.
回答3:
See this JSON Save Game example on serialization of an object to a JSON document.
回答4:
There are no internal tools in Qt to do it. You will have to use a lib. Or roll your own implementation