开发者

Xml to JSon, Character Problem

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

开发者_StackOverflow社区
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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜