kromain / qml-utils

A collection of QML utilities and snippets
MIT License
158 stars 60 forks source link

json array of numbers #1

Open alex-eri opened 11 years ago

alex-eri commented 11 years ago

not works: JSONListModel { json:'{"response":[5,467,2943,4424,13033]}' query: '$.response[*]' } with error: QML ListModel: append: value is not an object

ghost commented 11 years ago

Same error: JSONListModel { id: ratesModel source: "https://mtgox.com/api/1/BTCUSD/ticker" query: "$.return.high[*]" } error: file:///opt/btcmonitor/qml/btcmonitor/JSONListModel.qml:15:32: QML ListModel: append: value is not an object

ikt commented 10 years ago

So this is confirmation it can't handle arrays?

tyler-gilbert commented 8 years ago

This is how I handle arrays:

        var jo = objectArray[key];
        if( jo.toString() === "[object Object]"){
            jsonModel.append( jo );
        } else {
            //this is comma separated strings
            var str = jo.toString().split(",");
            for(var i = 0; i < str.length; i++){
                jsonModel.append({ "item": str[i] } );
            }
            break;
        }

The code does a check to see if the data is a classic object. If it isn't an object, it parses it as an array and uses "item" as the key.