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: 97
Registered: ‎11-13-2012
My Device: BB10 Simulator

[HELP] Parsing/Retrieving JSON from a file with Javascript. How to?

Please can you guys help? How can I do this in cascades with QML and Javascript and no C++? I am getting a headache with C++. I know there is a sample but it's writtin in C++ and QML. Please someone help? Thanks so much.

Developer
Developer
Posts: 174
Registered: ‎03-05-2009
My Device: Dev Alpha

Re: [HELP] Parsing/Retrieving JSON from a file with Javascript. How to?

did you look at the datasource class? 

https://developer.blackberry.com/cascades/documentation/device_platform/data_access/using_data_sourc...

 

look at the samples that uses datasource and replace the source to your json file.

 

all is done purely in javascript/qml.

 

one advice: if you don't feel like investing time in c++/Qt, then don't bother going native/cascades as it will only get worse...you simply cannot avoid the c++ code when going native!! 

webworks should be decent enough by now. You can also try other alternatives like blackberry-py (uses python code instead of c++, UI still in QML).

Developer
Posts: 97
Registered: ‎11-13-2012
My Device: BB10 Simulator

Re: [HELP] Parsing/Retrieving JSON from a file with Javascript. How to?

[ Edited ]

Thanks so much for that. saw it. But I think I cannot handle that json data very much. like looping to it manually.

 

I really want to learn C++ instead of purely QML because the syntax is pretty much little the same like Java & C#.

And I made this worked now:

 

Page *root = new Page;
ListView *listView = new ListView;
GroupDataModel *model = new GroupDataModel(QStringList() << "firstName" << "lastName");
JsonDataAccess jda;
QVariant list = jda.load(QDir::currentPath() + "/app/native/assets/employees.json");
qDebug() << "qvariant:" << list;
model->insertList(list.value<QVariantList>());
listView->setDataModel(model);
root->setContent(listView);
app->setScene(root);

 

I've searched for errors and fixed it. and now works great.!! the problem I am having now is the qDebug() not printing to the console. I already have updated my IDE.. now what to do guys. please?

Developer
Posts: 97
Registered: ‎11-13-2012
My Device: BB10 Simulator

Re: [HELP] Parsing/Retrieving JSON from a file with Javascript. How to?

Developer
Developer
Posts: 174
Registered: ‎03-05-2009
My Device: Dev Alpha

Re: [HELP] Parsing/Retrieving JSON from a file with Javascript. How to?

You can loop though the data in qml...

In the ondataloaded event of the datasource, you will get the data object as a javascript array. You can go through this array as yoy would with any javascript datastructure!

if you solved your issue, please mark this thread as solved!