PDA

View Full Version : sbjson - multi language




mpramodjain
Apr 28, 2011, 02:07 PM
Hi,

Had anyone had used multi-languages (other than english), mean unicode characters contained JSON with SBJSONParser, and had any luck with this parsing.

I tried but not getting the exact parsed content.

To say

I passed JSON Object containing Arabic text,

But it returns /u.. some other content.

Please let us know if anyone had got resolved this issue before.

Thanks.



mpramodjain
Jun 8, 2011, 01:05 PM
http://www.raywenderlich.com/1448/how-to-translate-text-with-google-translate-and-json-on-the-iphone

GOOGLE translator uses the SBJSON Parser. :)

PhoneyDeveloper
Jun 8, 2011, 05:06 PM
I believe that JSON uses UTF-8 text so there should be no problems at all with the parser. Are you sure that the JSON is valid UTF-8? I would inspect it before it's parsed.

One other thing, there are other available JSON parsing libraries and you might compare their output. I'm using JSONKit, which has been reported to be the fastest Obj-C JSON parser.

mpramodjain
Jun 10, 2011, 12:22 PM
I believe that JSON uses UTF-8 text so there should be no problems at all with the parser. Are you sure that the JSON is valid UTF-8? I would inspect it before it's parsed.

One other thing, there are other available JSON parsing libraries and you might compare their output. I'm using JSONKit, which has been reported to be the fastest Obj-C JSON parser.

Thanks for your reply PhoneyDev.

I am using SBJSON Parser, as it was much easier I found, and doesn't have much impact on my application.

Now I had tried Spanish language content parsing, it works fine. But where as I tried to parse the Arabic/Urdu content, I got the different parsed content as "\u\u".. like this,

Any idea ? why this happens.

PhoneyDeveloper
Jun 10, 2011, 05:33 PM
I don't have any idea why that happens. Have you printed out the JSON before it's parsed? Or save it to a file and open it in a UTF-8 aware text editor.

Are the escapes present in the JSON or are they added by the parser?

Hmmm, I just happened to be looking at some JSON from FaceBook and I see that there are escaped characters in it. I see them for curly quotes and a few other non-ascii special characters. I see something like "the world\u2019s best..." where I guess the escaped character is a curly quote. I haven't tried it but I assume that those characters are correctly parsed by all the usual parsers.

If you're really getting a result string that contains "\u\u" that sounds like a bug. Either the JSON is not valid or the parser has a bug.

One other question: where do you see the "\u\u"? In a textview or label or some other view on the device or in the debugger or in the debugger console? Is it possible that the phone doesn't have a font with the correct characters?