In my Blackberry application I am loading JSON using the following method.
private 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() ); } response = bsd.sendReceive(); _json = response.getObjectPayload(); } catch(Exception e) { System.out.println(e.toString()); } finally { if(bsd != null) { bsd.release(); } } return _json; }
This is working fine. But the problem is when I am getting JSON, Arabic characters show as junk
Arabic shows corrupted in the JSON output
As per the discussion, I encode the Arabic character into \uxxxx format(In my server side application) and it was working. But now I have to use a JSON from somebody else where I can’t change the server side code.
They are using asp.net C# , as per them they are sending the data like the following.
JsonResult result = new JsonResult(); result.ContentEncoding = System.Text.Encoding.UTF8; result.JsonRequestBehavior = JsonRequestBehavior.AllowGet; result.Data = “Data Object (Contains Arabic) comes here” return result;
So my question is, If the server provide the data in the above manner, BlockingSenderDestination.sendReceive method can get a utf-8 data? Or it is expecting only \uxxxx encoded data for non-ascii. Or I have to do something else (like sending some header to server) so that I can directly use the utf-8 data.
In debug mode I check the value of 'response'. It is already showing junk characters.
Except from JSON I am able to handle Arabic everywhere else.
Yesterday I posted this issue in Blackberry form . But till now no reply.
I am new to blackberry and Java. So I am sorry if this is silly question.
Thanks in advance.