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. QJsonDocument: JSON.parse() equivalence
QtWS25 Last Chance

QJsonDocument: JSON.parse() equivalence

Scheduled Pinned Locked Moved Unsolved General and Desktop
json parser
3 Posts 2 Posters 739 Views
  • 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.
  • G Offline
    G Offline
    GPBeta
    wrote on 14 Sept 2018, 10:03 last edited by
    #1

    Hello everyone.

    Because QJsonDocument::fromJSON() supports object and array types only,

    • number values: 1, 2.3
    • boolean values: true, false
    • string values: "foo", "bar"
    • null value: null

    strings above are recognized as invalid JSON documents.

    Also, instantiating QJSEngine and call JSON.parse() with string is not considered because it's too much overhead.

    So, I wonder does Qt has a simple solution that convert a string to JS value like JSON.parse() do?

    Any ideas are welcome :)

    \BAKA BAKA/

    1 Reply Last reply
    0
    • V Offline
      V Offline
      VRonin
      wrote on 14 Sept 2018, 10:37 last edited by VRonin
      #2

      Something like:

      • number values: QString::toInt()
      • boolean values: QString::compare("true")==0

      Your question is not really clear, where are you getting this values you want to parse from?

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      G 1 Reply Last reply 14 Sept 2018, 11:03
      1
      • V VRonin
        14 Sept 2018, 10:37

        Something like:

        • number values: QString::toInt()
        • boolean values: QString::compare("true")==0

        Your question is not really clear, where are you getting this values you want to parse from?

        G Offline
        G Offline
        GPBeta
        wrote on 14 Sept 2018, 11:03 last edited by
        #3

        @VRonin Hi, thank you for the reply.

        The values are from XML files and there're some text values which types are not declared in the document but must be one of the valid JS values.

        I don't really like to use QString based methods to parse them manually, not just I don't know the exact type of a value, but also there're some details behind the JSON.parse(), such as extra spaces, precision problems, etc.

        \BAKA BAKA/

        1 Reply Last reply
        0

        3/3

        14 Sept 2018, 11:03

        • Login

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