tags:

views:

26

answers:

1

hi, in my application I am doing conversion from, xml to Json object with this method;

JSONObject result = org.json.XML.toJSONObject(postData);

But, I have problems with turkish characters. It is not converting turkish characters from xml to json. How can I do this?

Thank you.

+1  A: 

I had a brief look at org.json.XML.toJSONObject(String) and it doesn't appear to be doing any character transcoding.

I suspect that the problem is in how your application is reading the String that is then being passed to toJSONObject. I suspect it is using the wrong character set.

There are actually two possibilities:

  1. The XML has no 'encoding' attribute and your application is just choosing the wrong one.

  2. The XML does have an 'encoding' attribute, but your application is unable to respect it.

The second possibility is problematical. In an ideal world, an XML document be parsed by reading as ASCII bytes until the 'encoding' attribute in the <? xml ?> declaration is read. Then character interpretation switches to the document's specified encoding. But the XML parser use byorg.json` is not capable of doing this, and its API doesn't allow this anyway. So if you have XML with an 'encoding' attribute, you'll have to detect it (by some means) before you turn the document into a Java String.

Stephen C