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: 123
Registered: ‎09-18-2013
My Device: Dev Alpha B
My Carrier: BSNL INDIA
Accepted Solution

load JSON file from assets

Hi, I have a JSON file that I placed in the assets folder. Now, how do I load it using JsonDataAccess..?? I mean, what URL should I use?
Developer
Posts: 543
Registered: ‎08-31-2013
My Device: Q10, Z10LE, Nokia N950, DAB....
My Carrier: Telekom Slovakia

Re: load JSON file from assets

app/native/assets/jsonfile.json

 https://developer.blackberry.com/native/documentation/cascades/device_platform/data_access/file_syst...



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: 123
Registered: ‎09-18-2013
My Device: Dev Alpha B
My Carrier: BSNL INDIA

Re: load JSON file from assets

So, instead of using QDir::home().file.json, I should use QDir::currentPath().app/native/assets/file.json Right?
Developer
Posts: 543
Registered: ‎08-31-2013
My Device: Q10, Z10LE, Nokia N950, DAB....
My Carrier: Telekom Slovakia

Re: load JSON file from assets

[ Edited ]

No, just use relative path

app/native/assets/file.json

 without QDir etc...



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: 123
Registered: ‎09-18-2013
My Device: Dev Alpha B
My Carrier: BSNL INDIA

Re: load JSON file from assets

I'll try and reply. I'm on mobile too. Smiley Happy
Developer
Posts: 1,746
Registered: ‎04-08-2010
My Device: Passport Silver, PRIV
My Carrier: Telekom.de, O2, Vodafone

Re: load JSON file from assets

I normaly use it this way to open files from assets or data

 

static QString dataAssetsPath(const QString& fileName) {
	return QDir::currentPath() + "/app/native/assets/datamodel/" + fileName;
}

static QString dataPath(const QString& fileName) {
	return QDir::currentPath() + "/data/" + fileName;
}

 then its easy stuff like

QString pathToItems = dataPath("items.json");
....
JsonDataAccess jda;
...
itemsList = jda.load(pathToItems).toList();

 

 

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development native Mobile Business Apps
BlackBerry 10 | Qt Mobile (Android, iOS)
Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org
mobile-development: http://appbus.org Twitter: @ekkescorner