简体   繁体   English

json_encode utf8

[英]json_encode utf8

I put some Data in my mysql DB that works fine. 我把一些数据放在我的mysql数据库中,运行正常。 But when I get the Data with json_encode I get ist back like this: 但是当我用json_encode获取数据时,我得到的回复如下:

{"idpostdata":"49","artID":null,"timestamp":"06.11.2012 13:35","lat":"51.496911","lon":"7.4022327","cellID":null,"road":"Wittener Stra\u00dfe","suburb":"Eichlinghofen","city":"Dortmund","postdatacol":null,"state_district":"Regierungsbezirk Arnsberg","state":"North Rhine-Westphalia","country_code":"de"}

you see "road":"Wittener Stra\ße" is not the correct name it must Wittener Straße 你看到"road":"Wittener Stra\ße"不是正确的名字它必须WittenerStraße

My Code: 我的代码:

<?php
$sql = mysql_query("SELECT * FROM postdata");

while ($ds = mysql_fetch_assoc($sql)) 
  $output[]=$ds;
echo "{uTraf:";
  print(json_encode($output));
echo  "}";
mysql_close($dz);
?>

What is wrong? 怎么了?

What is wrong? 怎么了?

Nothing. 没有。 \\uxxxx is JSON's way of encoding UTF-8 characters. \\uxxxx是JSON编码UTF-8字符的方式。

It will look all right again when you decode the JSON using a proper JSON decoding method. 当您使用适当的JSON解码方法解码JSON时,它会再次显示正常。

Nothing wrong it's part of the json_encoding to prevent faulty character conversion: 没有错,它是json_encoding的一部分,以防止错误的字符转换:

Look it up : \ß 查一查:\\ u00df

http://www.utf8-chartable.de/ http://www.utf8-chartable.de/

When you json_decode($string); 当你json_decode($string); it should be fixed again 它应该再次修复

Use addslashes when you save json data to mysql. 将json数据保存到mysql时使用addslashes。 And when you get data out, it is will be OK. 当你获得数据时,就可以了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM