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

Java Development

Reply
Contributor
jomy
Posts: 13
Registered: ‎02-08-2011
My Device: Bold 9780
My Carrier: Etisalat
Accepted Solution

Arabic shows corrupted in the JSON output

I am loading JSON using the following sample.


http://docs.blackberry.com/en/developers/deliverables/21128/Code_sample_Parse_JSON_data_structure_13...

 

It is working fine. But some fields are in Arabic. Those are showing as junk characters.  

 

الرئيس التنفيذي في «الاتصالات» السعودية: مفهوم التشبع [0.0] 

 

Is there any solution for this problem? Thanks in advance.

 

Thanks & Regards

 

Jomy

Please use plain text.
Developer
simon_hain
Posts: 15,845
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Arabic shows corrupted in the JSON output

welcome to the support forums.

 

how did you encode the arabic characters? to transfer them with json, xml or similar you could use unicode notation, for example. (\uxxxx)

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Contributor
jomy
Posts: 13
Registered: ‎02-08-2011
My Device: Bold 9780
My Carrier: Etisalat

Re: Arabic shows corrupted in the JSON output

I am using the following code to get JSON

 

 

 public static Object loadJson(String uriStr){
 Object _json = null;
        Message response = null;
        BlockingSenderDestination bsd = null;
        
        try
        {
            bsd = (BlockingSenderDestination)
                        DestinationFactory.getSenderDestination
                            ("CommAPISample", URI.create(uriStr));
            if(bsd == null)
            {
                bsd =
                  DestinationFactory.createBlockingSenderDestination
                      (new Context("CommAPISample"),
                       URI.create(uriStr), new JSONMessageProcessor()
                       );
            }
            // Send message and wait for response
            response = bsd.sendReceive();
            _json = response.getObjectPayload();
            
        }
        catch(Exception e)
        {
            System.out.println(e.toString());
        }
        finally
        {
            if(bsd != null)
            {
                bsd.release();
            }
        }
        return _json;
 }

 

 

 

Once i Got the JSON i am using the following code to parse it

 

 

     JSONObject tbl =  (JSONObject)JSONData;

     JSONArray tblAry = tbl.names();

        for(int i = 0; i < tblAry.length(); ++i)

        {

            try

            {

             Object rowData =  tbl.get(tblAry.getString(i));

             JSONObject row =  (JSONObject)rowData;

         String title = new String(getStringFromObj(row.get("Title")));

                String postedDate = getStringFromObj(row.get("PostedDate")); 

 add(new LabelField(title));

 add(new LabelField(postedDate ));

            }

            catch(JSONException e)

            {

                System.out.println(e.toString());

                continue;

            }

        }

------
getStringFromObj function
 String getStringFromObj(Object obj){
 String retVal = "";
        if(obj == null || obj.toString().equalsIgnoreCase("null") == false)
        {
         retVal = obj.toString();
        }
        return retVal;
 

 

-----

it is working fine. 'postedDate'  is showing well. But 'title' is in Arabic and it is showing as Junk

Please use plain text.
Contributor
jomy
Posts: 13
Registered: ‎02-08-2011
My Device: Bold 9780
My Carrier: Etisalat

Re: Arabic shows corrupted in the JSON output

When I Directly access the JSON through browser I am getting the following data. Where Arabic is coming well.

 

 

 

{"0":{"ArticleID":196385,"Title":"الرئيس التنفيذي في «الاتصالات» السعودية: مفهوم التشبع كالجبل الجليدي ونأمل بالدخول للسوق السورية","ArticleText":null,"Summary":" ","Source":"","ArticleSource":"","PostedDate":"2/8/2011","SummaryIsNull":"true","Index":0,"AssociatedImageID":1218,"HasAssociatedImage":"true","TitleLength":96,"Priority":0,"ArticleLink":null,"MoreArticlesCount":396,"CommentsCount":0},"1":{"ArticleID":196062,"Title":"نائب رئيس «الجذور العربية»: تحدي سوق المقاولات السعودية يكمن في «التنفيذ»","ArticleText":null,"Summary":" ","Source":"","ArticleSource":"","PostedDate":"2/6/2011","SummaryIsNull":"true","Index":1,"AssociatedImageID":1216,"HasAssociatedImage":"true","TitleLength":73,"Priority":0,"ArticleLink":null,"MoreArticlesCount":396,"CommentsCount":0},"2":{"ArticleID":196041,"Title":"جيرالد لوليس الرئيس التنفيذي لمجموعة جميرا لـ «البيان »: محمد بن راشد وراء نجاح القطاع السياحي في دبي","ArticleText":null,"Summary":" ","Source":"","ArticleSource":"","PostedDate":"2/6/2011","SummaryIsNull":"true","Index":2,"AssociatedImageID":1217,"HasAssociatedImage":"true","TitleLength":101,"Priority":0,"ArticleLink":null,"MoreArticlesCount":396,"CommentsCount":0},"3":{"ArticleID":196037,"Title":"محمد الحمراني مدير عام الغرفة في حوار مع الخليج: 4,4 مليار تجارة عجمان في 2010 بنمو 10% ","ArticleText":null,"Summary":" ","Source":"","ArticleSource":"","PostedDate":"2/6/2011","SummaryIsNull":"true","Index":3,"AssociatedImageID":null,"HasAssociatedImage":"false","TitleLength":88,"Priority":0,"ArticleLink":null,"MoreArticlesCount":396,"CommentsCount":0}}

Please use plain text.
Developer
simon_hain
Posts: 15,845
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Arabic shows corrupted in the JSON output

 

maybe you should work on some basics, read

http://en.wikipedia.org/wiki/Character_encoding

 

to transfer arabic characters (or anything else not ansi) you have to encode them. and decode them later, of course. usually utf8 is used for this.

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Contributor
jomy
Posts: 13
Registered: ‎02-08-2011
My Device: Bold 9780
My Carrier: Etisalat

Re: Arabic shows corrupted in the JSON output

Sorry I am new to Java and Blackberry. The same JSON works with IPHONE.

 

I will try to encode the JSON input and later decode it.

 

Thanks

Please use plain text.
Contributor
jomy
Posts: 13
Registered: ‎02-08-2011
My Device: Bold 9780
My Carrier: Etisalat

Re: Arabic shows corrupted in the JSON output

In JSON I encode Arabic text in \uxxxx format.And it is working. Thanks

Please use plain text.
Contributor
ashutosh_porchys
Posts: 29
Registered: ‎04-01-2011
My Device: 9800
My Carrier: torch

Re: Arabic shows corrupted in the JSON output

[ Edited ]

Hi,

     I am Also facing the same problem.

     my response of json is in arabic format but when I am going to display it .It is displaying with different format..الرئيس التنفيذي . Please send me some code so that I can continue with my work..

[Removed personal information to comply with Community Guidelines and Terms and Conditions of Use.]

 

Thanks in Advance.

Thanks
With Best Regards
Ashutosh Srivatava
Please use plain text.