How to convert a compact JSon String created by QJsonDocument::toJson(QJsonDocument::Compact) back to a JSon Object?
-
I was using QScriptEngine till now to parse and stringify JSon strings but after upgrading from QT4.8 to QT5.3, am observing a crash while using QScriptEngine. It seems a regression as per this bug:
https://qt.gitorious.org/qt/qtscript/commit/71f6dee8791c95fd862ca3651d7f4b7d6b9f440eI am trying to use QJsonDocument as an alternative to parse and stringify JSon. The problem that am facing is that our code and database is storing and utilizing compact strings and am not able to find a method to convert these compact strings back to JSon Objects.
Say for example,
QString sourceJson = {"Array": [true,999,"string"],"Key": "Value","null": null}
I am looking for way to convert above string to a QVariant (Map). Seems there is a way to convert a QJsonDocument to a compact string (using QJsonDocument::toJson(QJsonDocument::Compact)) but there is no reverse function.
QJsonDocument::fromJson function is probably only taking indented strings as inputs.
On a different note, since the patch is available for the bug that I have mentioned and using the patch, I can continue to use QScriptEngine, can some one please let me know if it is well within the licensing terms of commercial QT license to take the patch manually, recompile QT and ship our product?
Thanks a lot for your help.
Sachin
-
Hi,
[quote author="sachin.krverma" date="1410814818"]there is no reverse function.QJsonDocument::fromJson function is probably only taking indented strings as inputs.[/quote]What do you mean? JSON parsers handle both indented and compact inputs the same way. The following works just fine:
@
auto doc = QJsonDocument::fromJson(sourceJson.toUtf8());
@[quote author="sachin.krverma" date="1410814818"]can some one please let me know if it is well within the licensing terms of commercial QT license to take the patch manually, recompile QT and ship our product?[/quote]Yes, if you have a commercial license you can modify the Qt source code however you want.