[solved]JSON.parse ...need little help



  • we have reply.data

    @qml: Enginio finished:{
    "query": {
    "query": {},
    "limit": 100
    },
    "results": [
    {
    "population": 70,
    "raw": 19.2,
    "updatedAt": "2014-12-10T21:26:27.208Z",
    "updater": {
    "id": "5488b2cb5a3d8b0ee80654d3",
    "objectType": "users"
    },
    "water": 7.2
    }
    ]
    }@

    How do I use JSON.parse to get the value raw !?



  • Hi,

    If you use QML you can use JavaScript code:
    @
    var obj = JSON.parser(json_string);
    console.log("raw: "+obj.results[0].raw);
    @

    If you use C++ and Qt 5.x you can use QJsonDocument class:
    @
    QVariantMap res = QJsonDocument::fromJson(json_str).toMap();
    qDebug()<<"raw: "<<res["results"].toList()[0].toMap()["raw"].toDouble();
    @

    If you use C++ and Qt 4.x you need to use QJson lib from this "link":http://qjson.sourceforge.net.



  • thx :)



  • If your problem was solved please mark in your topic as solved.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.