json_encode 带有 mysql 内容和 utf-8 变音符号
当我试图找出这里的问题时,我感觉我的胡子在生长。
基本问题是,元音变音/特殊符号 äöß ... 不起作用。我想每个人都厌倦了这些问题,但网上找到的所有解决方案似乎都不起作用。
我在 utf-8 Mysql 数据库中有 utf-8 内容。我觉得问题出在数据库连接中的某个地方,但我就是无法弄清楚。
character_set_client utf8
字符集连接 utf8
字符集数据库utf8
字符集文件系统二进制文件
字符集结果 utf8
字符集服务器拉丁1
字符集系统 utf8
我不确定问题是否出在character_set_server的latin1上,因为我不喜欢mysql的东西。我也不知道如何更改,因为我无法访问 mysql 服务器的配置文件。
无论让我感到困惑的是,如果我从数据库中获取结果并回显它, print_r 就会给出正确的结果。
ini_set('default_charset','utf-8');
header('Content-Type: text/plain; > charset=utf-8');
Firefox 说 char 编码是 utf-8 但如果当我输出时:
print_r($listnew);
echo json_encode($listnew[5]);
print_r 结果一切正确,但 json_encode 错误。
print_r:
[5] => Array (
[id] => 5
[data] => U-Bahnhof Theresienstraße
[size] => 17
)
json_encode:
{"id":5,"data":"特莱西恩斯特拉地铁站","size":17}
我知道 json_encode 需要一个 utf-8 字符串才能在那里正常工作,我觉得我在这里遇到了编码问题,但我只是不知道它在哪里。
任何帮助将不胜感激,
提前致谢。
i3
i feel my beard growing while trying to find out the Problem here.
Basic the Problem is, that Umlauts/Special Signs äöß ... don't work. I guess everyone is sick and tired of that questions but all the solutions found online don't seem to work.
Im having utf-8 content in a utf-8 Mysql Database. I feel the Problem ist somewhere in the Database connection but i just can't figure out.
character_set_client utf8
character_set_connection utf8
character_set_database utf8
character_set_filesystem binary
character_set_results utf8
character_set_server latin1
character_set_system utf8
Im not sure if the problem is the latin1 for character_set_server because im not into that mysql stuff. I also dont know how to change cause i can't access the mysql server's config files.
Whatever is confusing me, that if i get my results from the Database and echo it, print_r gives the right result.
ini_set('default_charset','utf-8');
header('Content-Type: text/plain; > charset=utf-8');
Firefox says char encode is utf-8 but if when i output:
print_r($listnew);
echo json_encode($listnew[5]);
print_r results everything right but json_encode does wrong.
print_r:
[5] => Array (
[id] => 5
[data] => U-Bahnhof Theresienstraße
[size] => 17
)
json_encode:
{"id":5,"data":"U-Bahnhof Theresienstra\u00dfe","size":17}
i know json_encode needs a utf-8 string to work properly there and i feel im having a encode trouble here but i just can't firgure out where it is.
Any help would be appreciated,
thanks in advance.
i3
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯...我认为这实际上是正确的方式。
\u00df
是ß
的正确 unicode 表示形式。当您json_decode()
将其返回时,它将再次变为ß
。这在哪里给你带来了麻烦?是不是接收端没有正确解码?如果您使用标准
json_*
函数,则应该如此。手册中的所有示例都显示了相同的内容 - 超出 ASCII 范围的字符将转换为数字序列。
Ummm... I think that is the correct way actually.
\u00df
is a correct unicode representation ofß
. When youjson_decode()
it back, it will becomeß
again.Where is this making problems for you? Is the receiving end not decoding it properly? It should if you use standard
json_*
functions.All the examples in the manual show the same thing - characters beyond the ASCII range are turned into numeric sequences.