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
Highlighted
Developer
Posts: 73
Registered: ‎04-08-2014
My Device: Z10
My Carrier: XL

Working with JSON + QML

[ Edited ]

Hi everyone

im really stuck on showing my json in this below

ive already called my json and i dont know how to show it into my qml

here is my json

"{
"businessID":"2",
"name":"Bamboo Dim Sum",
"address":"Scientia Garden No 56",
"kelurahan":"Pagedangan",
"kecamatan":"SerpongUtara",
"noRate":"4",
"noReviews":null,
"phone1":null,
"phone2":null,
"phone3":null,
"reviews":null,
"description":null,
"longitude":null,
"latitude":null,
"items": [{"itemID":"1",
"name":"Dimsum Ceker",
"description":"Dimsum kaki ayam yang sangat lezat"],
}"

 and this is the way that i call my json above

void ApplicationUI::businessDetail(const QString& id, const QString& category, const QString& regionid)
{
    manager = new QNetworkAccessManager(this); // this can be also in app constructor

    QUrl url("my url");
    url.addQueryItem("method", "businessDetail");
    url.addQueryItem("id", id);
    url.addQueryItem("category", category);
    url.addQueryItem("regionid", "1");

    QNetworkRequest req(url);

    QNetworkReply *reply = manager->get(req);
    connect(reply, SIGNAL(finished()), this, SLOT(businessDetailFinished()));
}

how to parse every single json on above in my qml?

is there any example to show it?

thanks

 

Developer
Posts: 73
Registered: ‎04-08-2014
My Device: Z10
My Carrier: XL

Re: Working with JSON + QML (not listdataview)

anybody can help? thanks ive been 2 days working n still stuck

Developer
Posts: 435
Registered: ‎09-20-2011
My Device: Z10 LE, Playbook, DevAlpha C, 9900, 9380
My Carrier: Vodafone

Re: Working with JSON + QML (not listdataview)

void ApplicationUI::extractJsonData(){
    QString json = "{\"businessID\":\"2\",\"name\":\"Bamboo Dim Sum\",\"address\":\"Scientia Garden No 56\",\"kelurahan\":\"Pagedangan\",\"kecamatan\":\"SerpongUtara\","
            "\"noRate\":\"4\",\"noReviews\":null,\"phone1\":null,\"phone2\":null,\"phone3\":null,\"reviews\":null,\"description\":null,\"longitude\":null,\"latitude\":null,"
            "\"items\":[{\"itemID\":\"1\",\"name\":\"Dimsum Ceker\",\"description\":\"Dimsum kaki ayam yang sangat lezat\"}]}";

    bb::data::JsonDataAccess ja;
    const QVariant jsonva = ja.loadFromBuffer(json);
    QVariantMap map1 = jsonva.toMap();

    QVariant businessID = map1.value("businessID");
    qDebug()<<"businessID"<<businessID.toString();
    QVariant address = map1.value("address");
    qDebug()<<"Address"<<address.toString();
    ///Similarly do the rest of the tags

    QVariant items = map1.value("items");
    QList<QVariant> itemslist = items.value<QVariantList>();
    int i;
    for(i=0;i<itemslist.length();i++){
         QVariant map2 = itemslist.at(i);
         QVariantMap listdata = map2.toMap();
         qDebug()<<"item itemID"<<listdata.value("itemID").toString();
         qDebug()<<"item name"<<listdata.value("name").toString();
         qDebug()<<"item description"<<listdata.value("description").toString();
    }
}

 

Developer
Posts: 73
Registered: ‎04-08-2014
My Device: Z10
My Carrier: XL

Re: Working with JSON + QML (not listdataview)

up

Developer
Posts: 73
Registered: ‎04-08-2014
My Device: Z10
My Carrier: XL

Re: Working with JSON + QML (not listdataview)

thanks

but, what should i write to call those function into my qml?

Developer
Posts: 435
Registered: ‎09-20-2011
My Device: Z10 LE, Playbook, DevAlpha C, 9900, 9380
My Carrier: Vodafone

Re: Working with JSON + QML (not listdataview)

Developer
Posts: 73
Registered: ‎04-08-2014
My Device: Z10
My Carrier: XL

Re: Working with JSON + QML (not listdataview)

bb::data&colon;:JsonDataAccess ja;

 this line is syntax error

how can i fix it?

Developer
Posts: 543
Registered: ‎08-31-2013
My Device: Q10, Z10LE, Nokia N950, DAB....
My Carrier: Telekom Slovakia

Re: Working with JSON + QML (not listdataview)

[ Edited ]
bb::data&colon;:JsonDataAccess ja;

 



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
My Carrier: Vodafone

Re: Working with JSON + QML (not listdataview)

[ Edited ]

replace ":" for "&colon;"