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
Posts: 435
Registered: ‎09-20-2011
My Device: Z10 LE, Playbook, DevAlpha C, 9900, 9380
Accepted Solution

How to create a Json structure programatically in Qt

Hi all,

 

I know to parse a json structure but not the reverse.

Below is the structure i need to create.

 

{"3":["Num Accounts","1"],"2":["Version","1"],"1":["OS,BB10","10.2.1.0"],"4":["Locale","en_GB"]}

 

Can any one point me how to do it in standard way.

Developer
Posts: 540
Registered: ‎08-31-2013
My Device: Q10, Z10LE, Nokia N950, DAB....

Re: How to create a Json structure programatically in Qt

QVariantMap map;

QVariantList list;
list << "Num Accounts" << "1";
QVariantList list2;
list2 << "Version" << "1";
QVariantList list3;
list3 << "OS,BB10" << "10.2.1.0";
QVariantList list4;
list4 << "Locale" << "en_GB";

map.insert("3", list);
map.insert("2", list2);
map.insert("1", list3);
map.insert("4", list4);

 



If helped give a like. If your problem was solved mark the post as "Solution"
Portfolio: BlackBerry Nokia
Social: Twitter | Facebook
About Me / Blog DevPDA | Blog
Developer
Posts: 435
Registered: ‎09-20-2011
My Device: Z10 LE, Playbook, DevAlpha C, 9900, 9380

Re: How to create a Json structure programatically in Qt

[ Edited ]

Hi @benecore, i have done this but i need to serialize output.

Developer
Posts: 540
Registered: ‎08-31-2013
My Device: Q10, Z10LE, Nokia N950, DAB....

Re: How to create a Json structure programatically in Qt

look here

https://developer.blackberry.com/native/reference/cascades/bb__data__jsondataaccess.html#function-sa...

 

QByteArray buffer;
JsonDataAccess jda;
jda.saveToBuffer(QVariant(map), &buffer);
qDebug() << buffer;

 



If helped give a like. If your problem was solved mark the post as "Solution"
Portfolio: BlackBerry Nokia
Social: Twitter | Facebook
About Me / Blog DevPDA | Blog
Developer
Posts: 435
Registered: ‎09-20-2011
My Device: Z10 LE, Playbook, DevAlpha C, 9900, 9380

Re: How to create a Json structure programatically in Qt

Wow, that was a great help!!! Thanks.
Developer
Posts: 540
Registered: ‎08-31-2013
My Device: Q10, Z10LE, Nokia N950, DAB....

Re: How to create a Json structure programatically in Qt

You're welcome



If helped give a like. If your problem was solved mark the post as "Solution"
Portfolio: BlackBerry Nokia
Social: Twitter | Facebook
About Me / Blog DevPDA | Blog