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: 126
Registered: ‎06-25-2013
My Device: Z10
My Carrier: none

Unable to Extract JSON values from a json string received from server with OS 10.2.0.484 on phone

[ Edited ]

i used this code 

 

QString jsonObject = "{"firstName":"sanjeev", "lastName":"kumar"} ";
//some valid json from server
JsonDataAccess jda;
QVariant list = jda.loadFromBuffer(jsonObject);
QString val1 = list.toMap().values("firstName").value(0).toString();
QString val2 = list.toMap().values("lastName").value(0).toString();

qDebug () << "The Name is " << val1 << " " << val2;

// on phone OS 10.1.0.xxx it was printing fine  as The name is "sanjeev kumar"
// on phone OS 10.2.0.424 is is printing The Name is ""

 is there any changes in how to use a QVariant ?

 

 

Highlighted
BlackBerry Development Advisor
Posts: 143
Registered: ‎03-08-2012
My Device: Z10
My Carrier: Bell

Re: Unable to Extract JSON values from a json string received from server with OS 10.2.0.484 on phone

I'm surpirsed your code compiles.  You do not have your quotes escaped on the first line.  I changed it as follows:

 

    QString jsonObject = " { \"firstName\":\"sanjeev\", \"lastName\":\"kumar\" } ";
    //some valid json from server
    JsonDataAccess jda(this);
    QVariant list = jda.loadFromBuffer(jsonObject);
    QString val1 = list.toMap().values("firstName").value(0).toString();
    QString val2 = list.toMap().values("lastName").value(0).toString();

    qDebug () << "The Name is " << val1 << " " << val2;

and this was the result:

 

The Name is  "sanjeev"   "kumar"

I tested this on the same OS as indicated below.

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

Re: Unable to Extract JSON values from a json string received from server with OS 10.2.0.484 on phone

Hi,

 

jsonObject  is a json received from the server response.

 

I had some other issue while using the json string.

 

Regards,

Sanjeev

BlackBerry Development Advisor
Posts: 143
Registered: ‎03-08-2012
My Device: Z10
My Carrier: Bell

Re: Unable to Extract JSON values from a json string received from server with OS 10.2.0.484 on phone

Can you post the json response (or qquivalent with test data) so that I can try parsing it with the same code?  Thanks.