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\u00dfe" 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?
3 Answers 3
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.
Comments
Nothing wrong it's part of the json_encoding to prevent faulty character conversion:
Look it up : \u00df
When you json_decode($string); it should be fixed again
Comments
Use addslashes when you save json data to mysql. And when you get data out, it is will be OK.
\u00dfis the JSON escape sequence for the German sharp S (ß). The question is rather is the escaping really needed and if not how can it be avoided.