PDA

View Full Version : How to access key and value in QvariantMap?



Mathan
27th September 2016, 17:17
Hi,

I had assigned the value from the Json to QvariantMap. I can see the values are stored in Key and Value pairs.
Query: How to fetch the value?

in main.qml

var jsontext = '[{"firstname":"Jesper","surname":"Aaberg","phone":"555-0120"},{"firstname":"Jesperuu","surname":"Aaberguu","phone":"55665-0120"}]';


12129

anda_skoa
27th September 2016, 19:21
In C++ you can use either the index operator or the value method to do a key lookup.
E.g.


QVariant someValue = variantMap.value(someKey);


In QML/JavaScript I think you can also use the index operator or the key as a property name,
e.g.


var someValue = variantMap[someKey];


The script environment can also deal with JSON directly as far as I know.

Cheers,
_