I am writing a webservice that uses json to represent its resources, and I am a bit stuck thinking about the best way to encode the json. Reading the json rfc (http://www.ietf.org/rfc/rfc4627.txt) it is clear that the preferred encoding is utf-8. But the rfc also describes a string escaping mechanism for specifying characters. I assume this would generally be used to escape non-ascii characters, thereby making the resulting utf-8 valid ascii.
So let's say I have a json string that contains unicode characters (code-points) that are non-ascii. Should my webservice just utf-8 encoding that and return it, or should it escape all those non-ascii characters and return pure ascii?
我希望浏览器能够使用JSONP或eval执行结果.这会影响这个决定吗?我对各种浏览器对utf-8的javascript支持缺乏了解.
编辑:我想澄清一下,我主要关心的是如何对结果进行编码,实际上是浏览器对结果的处理.我读到的内容表明,浏览器在使用JSONP时可能对编码非常敏感.我还没有找到任何关于这个主题的好信息,所以我必须开始做一些测试,看看会发生什么.理想情况下,我只想转义所需的几个字符,并对结果进行utf-8编码.