1 Attachment(s)
How to access key and value in QvariantMap?
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"}]';
Attachment 12129
Re: How to access key and value in QvariantMap?
In C++ you can use either the index operator or the value method to do a key lookup.
E.g.
Code:
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.
Code:
var someValue = variantMap[someKey];
The script environment can also deal with JSON directly as far as I know.
Cheers,
_