2

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?

asked Nov 6, 2012 at 13:04
1
  • It's not incorrect since \u00df is 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. Commented Nov 6, 2012 at 13:10

3 Answers 3

10

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.

community wiki

Sign up to request clarification or add additional context in comments.

Comments

1

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

Look it up : \u00df

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

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

answered Nov 6, 2012 at 13:08

Comments

-1

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

answered Jul 4, 2014 at 9:32

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.