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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
Developer
Posts: 126
Registered: ‎06-25-2013
My Device: Z10
My Carrier: none
Accepted Solution

How to extract data from json string where value in an array

Hi,

 

JSON String Structure

 

{"name" : "sanjeev" , "surname" : "kumar" , "address" : [{ "address1" : "value" ,  "place" : "value" }, { "address2" : "value" , "place" : "value" }] }

 


how to extract address value to list.

 

Developer
Posts: 1,746
Registered: ‎04-08-2010
My Device: Passport Silver, PRIV
My Carrier: Telekom.de, O2, Vodafone

Re: How to extract data from json string where value in an array

JsonDataAccess will give you a QVariantMap

and from this map you can get a QVariantList for 'address'

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development native Mobile Business Apps
BlackBerry 10 | Qt Mobile (Android, iOS)
Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org
mobile-development: http://appbus.org Twitter: @ekkescorner
Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: How to extract data from json string where value in an array

Developer
Posts: 126
Registered: ‎06-25-2013
My Device: Z10
My Carrier: none

Re: How to extract data from json string where value in an array

i can extract value of name, surname by using JsonDataAccess

 

JsonDataAccess jda;

QVariant list = jda.loadFromBuffer(jsonString); 

QString name = list.toMap().values("name").value(0).toStrinng();

QString surname = list.toMap().values("surname").value(0).toStrinng();

 

 

Now my question is how to get the value of address in the jsonString which is an array .

Highlighted
Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: How to extract data from json string where value in an array

[ Edited ]

If you have control over the data format, it's better to rename address1 and address2 to have the same name, for example "address". Then it can be parsed like this (I've also simplified other code a bit):

 

JsonDataAccess jda;
QVariant v = jda.loadFromBuffer(jsonString);
QVariantMap m = v.toMap();
QString name = m["name"].toString();
QString surname = m["surname"].toString();
QVariantList addresses = m["address"].toList();
foreach (QVariant addr, addresses)
{
QVariantMap addrMap = addr.toMap(); QString addressValue = addrMap["address"].toString(); QString place = addrMap["place"].toString(); }

 


Andrey Fidrya, @zmeyc on twitter