Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. QML and JSON
Forum Updated to NodeBB v4.3 + New Features

QML and JSON

Scheduled Pinned Locked Moved QML and Qt Quick
23 Posts 12 Posters 54.6k 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.
  • C Offline
    C Offline
    Chuck Gao
    wrote on last edited by
    #21

    I think the simplest way to parse and turn json data to C++ model is using QScriptEngine. Please see:
    @
    QScriptValue json = m_scriptEngine->evaluate("JSON.parse").call(QScriptValue(), QScriptValueList() << jsonString);
    QVariantList xxxList = json.toVariant().toList();
    or
    QVariantMap xxxMap = json.toVariant().toMap();
    .....
    Then, do parse
    .....
    @

    And, in the code, m_scriptEngine is your QScriptEngine, and jsonString is your json data

    Chuck

    1 Reply Last reply
    0
    • F Offline
      F Offline
      fcrochik
      wrote on last edited by
      #22

      QML "includes" a JSON parser. You can just use, without having to include anything:

      @var obj = JSON.parse( myJSONString );@

      "See json.org for more details":http://www.json.org/js.html

      Of course eval can do the trick as well but it is risky and the JSON parser maybe optimized.

      Certified Specialist & Qt Ambassador <a href="http://www.crochik.com">Maemo, Meego, Symbian, Playbook, RaspberryPi, Desktop... Qt everywhere!</a>

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kromain
        wrote on last edited by
        #23

        For anybody still interested, I've just published a JSONListModel component that works just like XMLListModel, but for JSON data instead. It's all pure QML/Javascript, and it even supports queries via JSONPath (XPath for JSON).

        You can read more about it there: "Devnet article":http://qt-project.org/wiki/JSONListModel

        Romain Pokrzywka
        KDAB - http://www.kdab.com

        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