php json_decode utf8 problem
I have a json encoded entry in my MySQL
[{"0":{"town":"İstanbul","location":1},"1":{"town":"Eskişehir开发者_JAVA百科","location":1},"orderDay":"2011-09-20"}]
When I get this data from Mysql I get it as it is. Exactly same. But when I try to decode it, utf8 chars changes. Like "İ" or "ş" doesnt decode as they are. They look something like "u015f"
My MySql is utf8. And my rows are also utf8. I have
header('Content-Type: text/html; charset=utf-8');
at the top of my php file. I also have
mysql_query( "SET NAMES 'utf8' " );
after I connected to the database.
So what should I do to decode my data with utf8 chars?
encoding an decoding of accented character seems to work correctly here
http://codepad.org/7Uh9R3fY
with this code
<?
$str = json_encode(array(name => 'ş'));
echo $str;
print_r(json_decode($str));
?>
and if you see "u015f" as the value then you are probably missing a forward slash before this escape sequence, so are you sure that your code is not removing that slash?
If you use your browser to look at this try setting encoding to either UTF8 or autodetect. In Chrome this is done at Tools -> Encoding
精彩评论