php json_decode utf8问题
我的 MySQL 中有一个 json 编码条目,
[{"0":{"town":"İstanbul","location":1},"1":{"town":"Eskişehir","location":1},"orderDay":"2011-09-20"}]
当我从 Mysql 获取此数据时,我按原样得到它。完全一样。但是当我尝试解码它时,utf8 字符发生了变化。就像“ı”或“ş”不能按原样解码。它们看起来像“u015f”,
我的 MySql 是 utf8。我的行也是utf8。 有
header('Content-Type: text/html; charset=utf-8');
我的 php 文件的顶部 也有
mysql_query( "SET NAMES 'utf8' " );
。我连接数据库后
。那么我应该怎么做才能用 utf8 字符解码我的数据呢?
I have a json encoded entry in my MySQL
[{"0":{"town":"İstanbul","location":1},"1":{"town":"Eskişehir","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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对重音字符进行解码似乎可以正常工作
http://codepad.org/7Uh9R3fY
使用此代码
如果如果您看到“u015f”作为值,那么您可能在此转义序列之前缺少一个正斜杠,所以您确定您的代码没有删除该斜杠吗?
encoding an decoding of accented character seems to work correctly here
http://codepad.org/7Uh9R3fY
with this code
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?
如果您使用浏览器查看此内容,请尝试将编码设置为 UTF8 或自动检测。在 Chrome 中,这是在“工具”->“工具”中完成的。编码
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