I would like to append an answer in JSON from a web server to a QML ListModel. Currently I am using
eventModel.append(jsonObject)
which works fine if the answer only contains strings or numbers but not if there is an array within the answer. I am using the code from here to get the JSON object.
This is one line of the answer:
{"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":""}]}
Everything is added fine beside z. If I read the entries from the list model I get this:
{"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}}
It looks like everything in z is lost. I already tried to add it again
for(var i in jsonObject){
eventModel.append(jsonObject[i])
eventModel.set(i, {"z":jsonObject[i]["z"]})
}
but the result is the same.
Is something like this just not possible or am I doing something wrong here when appending the JSON object to the list model?
ListModelcontains list ofListElementitems. According to docs it can contain only simple values -Values must be simple constants; either strings, boolean values, numbers, or enumeration values. Value you try to assign tozis object or array. - folibiseventModel.set(i, {"zn":jsonObject[i]["z"][0]})zn is added as array and I have all values. Maybe 2D arrays (or what ever z currently is) cannot be added to a ListModel but arrays do work. - SikarjanListElementget as arrays as objects. For example it eat thatmodel.append({param: {a: 1, b: 2}})w/o problem. Arrays also are acceptable:model.append({param: [1,2]}). - folibis