json array of numbers #1

Open
alex-eri opened this Issue Jan 28, 2013 · 3 comments

Comments

Projects
None yet
4 participants

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

paulo commented Feb 23, 2013

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 Aug 10, 2014

So this is confirmation it can't handle arrays?

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment