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: 275
Registered: ‎02-05-2010
My Device: Blackberry Z10
My Carrier: Bouygues Telecom

Listview items with unicode characters

Hi,
I'm struggling with unicode characters...
Based on the bucketlist sample, I'm creating a new file from a json packaged with my app.
My json file contains unicode characters representing smileys, here's a few ones :

[
{ "category":"Smiling, happy","title":"\u263B\u005F\u263B"},
{ "category":"Smiling, happy","title":"\u263A"},
{ "category":"Smiling, happy","title":"\u263B"},
{ "category":"Smiling, happy","title":"\u0028\u2022\u02C6\u2323\u02c6\u2022\u0029"},
{ "category":"Smiling, happy","title":"\\\u263A\/"},
{ "category":"Smiling, happy","title":"\u0028\uF8E7\u0027\u2323\u0027\uF8E7\u0029"},
{ "category":"Smiling, happy","title":"\u06F0\u2022\u00B0\u2022\u06F0\u005B\u0048\u0305\u0332\u0041\u0305\u0332\u0050\u0305\u0332\u0050\u0305\u0332\u0059\u0305\u0332\u005D\u06F0\u2022\u00B0\u2022\u06F0"},
{ "category":"Smiling, happy","title":"\u2022\"\u032E\u2022"},
{ "category":"Smiling, happy","title":"\u2649\u0028\u02C6\u25BD\u02C6\u0029\u2649"},
{ "category":"Smiling, happy","title":"\u0028\u00BB\u0027\u2323\u0027\u00AB\u0029"}
]

When the app starts (first launch only), I'm creating a file based on the above json :

QStringList pathSplit = mJsonAssetsPath.split("/");
QString fileName = pathSplit.last();
QString dataFolder = QDir::homePath();
mJsonDataPath = dataFolder + "/" + fileName;
QFile newFile(mJsonDataPath);

Then I'm loading it in my QVariantList
mData = jda.load(mJsonDataPath).value<QVariantList>();

and I fill my QListDataModel like this :

foreach(QVariant v, mData){
    append(v.toMap());
}

Some unicode characters are well displayed, some are not because I get crossed squared characters.
Maybe it's related with UTF-8 or UTF-16 encoding.

As the JsonDataAccess load documentation says :

The file data can be encoded as UTF-8 (with or without byte-order-mark) or as UTF-16 (must have a byte-order-mark to indicate little endian or big endian).

But how and when should I mention a byte-order-mark ? In the json file packaged with my app ? When I create the new file on the file system ? When I load it ?

Thank you for your help,

Laurent

Twitter : @LaurentKP
My apps
Developer
Posts: 87
Registered: ‎07-23-2009
My Device: Z30
My Carrier: XL

Re: Listview items with unicode characters

It is happen to me after update Dev Alpha OS today, some unicode character (arabic) become crossed squared characters :smileysad: 

I think we should report it in jira

Developer
Posts: 275
Registered: ‎02-05-2010
My Device: Blackberry Z10
My Carrier: Bouygues Telecom

Re: Listview items with unicode characters

I think it's not the same issue because I've not yet updated the sdk nor the alpha device.
Are you providing a listview from a json file too ?
Twitter : @LaurentKP
My apps
Developer
Posts: 87
Registered: ‎07-23-2009
My Device: Z30
My Carrier: XL

Re: Listview items with unicode characters

I see

no, in my app the data is come from local database.

Contributor
Posts: 26
Registered: ‎12-11-2012
My Device: 9900
My Carrier: Rogers

Re: Listview items with unicode characters

I use utf-8 in my XML file for list view and there's no problem. Windows eclipse needs a change from default to display them properly in the debug console but there is no problem on the alpha device.
Developer
Posts: 275
Registered: ‎02-05-2010
My Device: Blackberry Z10
My Carrier: Bouygues Telecom

Re: Listview items with unicode characters

UTF-8 is ok. I think the trouble is with UTF-16 characters. When I'm home I'll check and isolate the bad characters.
Twitter : @LaurentKP
My apps
Contributor
Posts: 26
Registered: ‎12-11-2012
My Device: 9900
My Carrier: Rogers

Re: Listview items with unicode characters

Bom mark is 2 or 3 bytes at the beginning of a text file. Use a good text editor and you can set it usually as encoding.
Developer
Posts: 275
Registered: ‎02-05-2010
My Device: Blackberry Z10
My Carrier: Bouygues Telecom

Re: Listview items with unicode characters

I wrote my json file with notepad++ encoding is ansi.
Twitter : @LaurentKP
My apps
Contributor
Posts: 26
Registered: ‎12-11-2012
My Device: 9900
My Carrier: Rogers

Re: Listview items with unicode characters

\uXXXX may not work unlike in java. If you paste the utf-16 chars directly and save-as utf-16, it may.
Developer
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10
My Carrier: none

Re: Listview items with unicode characters

I don't believe there is any need for a BOM when using JSON with text defined using the \uXXXX escape sequence, since the source text is all ASCII. It's only when it gets parsed that the text is converted to Unicode chars (in the QStrings) and that shouldn't be anything that needs a BOM.

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!