views:

30

answers:

3

When I use json_encode to encode my multi lingual strings , It also changes special characters.What should I do to keep them same .

For example

<?
echo json_encode(array('şüğçö'));

It returns something like ["\u015f\u00fc\u011f\u00e7\u00f6"]

But I want ["şüğçö"]

A: 

json_encode() does not provide any options for choosing the charset the encoding is in.

Ignacio Vazquez-Abrams
+1  A: 

In JSON any character in strings may be represented by a Unicode escape sequence. Thus "\u015f\u00fc\u011f\u00e7\u00f6" is semantically equal to "şüğçö".

Although those character can also be used plain, json_encode probably prefers the Unicode escape sequences to avoid character encoding issues.

Gumbo
A: 
<?php

print_r(json_decode(json_encode(array('şüğçö'))));

/*
Array
(   
    [0] => şüğçö
)
*/

So do you really need to keep these characters unescaped in the JSON?

Romain Deveaud
yes because I pass it to HTML via ajax request , and I can not see special characters
Oguz
@Oguz: Ajax (e.g. asynchronous requests via JavaScript) do not depend on JSON.
Gumbo