I was working on project that had problem when encoding UFT-8 text into JSON Format
and i also tried Zend_JSON Library ,
in both cases the JSON output was crazy :
{"wine":"\u0639\u0631\u0628\u064a ","\u0639\u0631\u0628\u064a":4,"lemon":22}
i did try it into PHP5.2.6 and PHP5.3 but same result ..
How do I convert UTF-8 text into JSON? Any suggestions?
That's a unicode notation understood by javascript/ecmascript. Try
<html> <head> <title>unicode test</title> <script type="text/javascript"> function foo() { var outDiv = document.getElementById("bar"); var jsondata = {"wine":"\u0639\u0631\u0628\u064a ","\u0639\u0631\u0628\u064a":4,"lemon":22}; for ( var k in jsondata ) { outDiv.innerHTML += k + "=" + jsondata[k] + "<br />"; } } </script> </head> <body onload="foo()"> <div id="bar"></div> </body> </html>
to see for yourself.
http://www.ecmascript.org/docs/tc39-2009-043.pdf (page 14) :
In string literals, regular expression literals, and identifiers, any character (code unit) may also be expressed as a Unicode escape sequence consisting of six characters, namely \u plus four hexadecimal digits.
What exactly is crazy about the output?
var b = {"wine":"\u0639\u0631\u0628\u064a ", test:"\u0639\u0631\u0628\u064a","lemon":22}; alert (b.wine);