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. Parsing JSON with QML
Forum Update on Tuesday, May 27th 2025

Parsing JSON with QML

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
json
3 Posts 2 Posters 4.6k Views 2 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
    Sikarjan
    wrote on 11 Nov 2016, 22:22 last edited by
    #1

    Hi,

    I found the best answer to this question in this post: Parsing Json with QML but it is already five years old and I was wondering if there is a better way with QtQuick 2.0.

    There is one issue in particular. If the JSON response is an array the information in the array is lost. This JSON stream:

    {"i":3814086,"t":"d","s":1479970800,"sw":"Do","sds":"24.11.16","ss":"08:00","e":1479996000,"eds":"24.11.16","es":"15:00","f":false,"z":[{"i":223500,"d":true,"r":"","h":null,"hs":null,"hss":"","he":null,"hes":""}]}
    

    Looks like this in the model:

    {"objectName":"","i":3814086,"t":"d","s":1479970800,"sw":"Do","sds":"24.11.16","ss":"08:00","e":1479996000,"eds":"24.11.16","es":"15:00","f":false,"z":{"objectName":"","count":1,"dynamicRoles":false}}
    

    How can I add the stream to the list model so that z is not lost?

    1 Reply Last reply
    0
    • B Offline
      B Offline
      benlau
      Qt Champions 2016
      wrote on 13 Nov 2016, 08:57 last edited by
      #2

      There has many methods listed in the article. I am not sure which one you mean, but JSON.parse() do not work?

      1 Reply Last reply
      0
      • S Offline
        S Offline
        Sikarjan
        wrote on 13 Nov 2016, 14:29 last edited by
        #3

        Hi,

        I am using the one dridk mentioned. The parsing works fine and I use

        listModel.append({jsonObject});
        

        to fill my ListView. Everything is in the ListModel besides z.
        If I do:

            for(var i in jsonObject){
                eventModel.append(jsonObject[i])
                eventModel.set(i, {"zn":jsonObject[i]["z"][0]})
            }
        

        z is added as an array. Just like in the JSON object just without the []-brackets.

        1 Reply Last reply
        0

        1/3

        11 Nov 2016, 22:22

        • Login

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