Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Contributor
Posts: 17
Registered: ‎07-31-2013
My Device: Q10
My Carrier: T-Mobile

Add item to QMap

Hi,

i want to add an item to my Data Source but i don't know how to do it.

For example if the data source looks like this how can i add to each item "country":"USA"

{
  "city": [
    {
      "name": New York",
    },
    {
      "name": Philadelphia",
    }  
]
}

 

 

i tried

 

JsonDataAccess jda;

QVariant main = jda.loadFromBuffer(buffer);

QVariantMap mainMap = main.value<QVariantMap>();

for(int i = 0; i < mainMap["city"].toList().length(); i++){

mainMap["city"].toList().at(i).toMap().insert("country",QVariant("USA"));
}

 but this doesn't work.

thanks in advance

Developer
Posts: 71
Registered: ‎05-21-2012
My Device: DA C, Z10 LE, Passport
My Carrier: TIM

Re: Add item to QMap

you can try to use something like:

 

QVariant main = jda.loadFromBuffer(buffer);
QVariantList mainMap = main.toMap().value("city").toList();
QVariantMap item;
item.insert("country", "USA");
mainMap << item;