Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to convert a compact JSon String created by QJsonDocument::toJson(QJsonDocument::Compact) back to a JSon Object?
Forum Updated to NodeBB v4.3 + New Features

How to convert a compact JSon String created by QJsonDocument::toJson(QJsonDocument::Compact) back to a JSon Object?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 2.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sachin.krverma
    wrote on last edited by
    #1

    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/71f6dee8791c95fd862ca3651d7f4b7d6b9f440e

    I 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

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      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.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved