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
Developer
babakar
Posts: 718
Registered: ‎05-29-2012
My Device: see later
My Carrier: see later
Accepted Solution

parsing json file

{"employees": [
   {
      "employeeNumber": "00697071617",
      "balance": "422,846.58"
   },
   {
      "employeeNumber": "00697071617",
      "balance": "422,846.58"
   }
]}

 

JsonDataAccess jda;
	QVariant jsonva = jda.load(
			QDir::currentPath() + "/app/native/assets/account.json");

	QVariantList list = jsonva.toList();

QVariant childJsonva = list.at(0);
		QVariantList childList = childJsonva.toList();
		for (QList<QVariant>::iterator it = childList.begin(); it != childList.end();
				it++) {
			qDebug() << "unknown stateeee";
			map = it->toMap();
			qDebug() << "unknown state";
			listModel->append(map);
		}

 

 

how can i fix bolded part? I am never able to get to the for loop inside employees...

no list is seen..application crashes on bolded part..

other ways i try..i am never able to get to the loop inside employees

Please use plain text.
Developer
babakar
Posts: 718
Registered: ‎05-29-2012
My Device: see later
My Carrier: see later

Re: parsing json file

QVariant jsonva = jda.load(
			QDir::currentPath() + "/app/native/assets/account.json");

	//QVariantList list = jsonva.toList;
	QVariant list = jsonva;

QVariant childJsonva = list.at(0);
		QVariantList childList = childJsonva.toList();
		for (QList<QVariant>::iterator it = childList.begin(); it != childList.end();
				it++) {

 

 

alll i wanna know, how can i read inside accounts..

Please use plain text.
Developer
simon_hain
Posts: 16,042
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: parsing json file

check the size of "list", does it contain the employees?
what is the size of childList?
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
babakar
Posts: 718
Registered: ‎05-29-2012
My Device: see later
My Carrier: see later

Re: parsing json file

[ Edited ]

solved

 

QVariantMap childJsonv1a = list.toMap();
		QVariant  childJsonva = childJsonv1a["employees"];
		QVariantList childList = childJsonva.toList();

 

get it as qvariantmap

Please use plain text.