简体   繁体   中英

json_encode utf8

I put some Data in my mysql DB that works fine. But when I get the Data with json_encode I get ist back like this:

{"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

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.

It will look all right again when you decode the JSON using a proper JSON decoding method.

Nothing wrong it's part of the json_encoding to prevent faulty character conversion:

Look it up : \ß

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

When you json_decode($string); it should be fixed again

Use addslashes when you save json data to mysql. And when you get data out, it is will be OK.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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