Setting header to Content-Type: application/json
I got response clearly in iso-8859-1
in all browsers. The default_charset
is set to utf-8
. Adding charset=utf-8
fixes the problem, but I don't understand why do I have to set the charset if an application/json
default charset is utf-8
.
Asked
Active
Viewed 1,639 times
0

Remy Lebeau
- 555,201
- 31
- 458
- 770

zogby
- 462
- 4
- 15
-
Where do you set the default encoding? What is the overall architecture of your system? Please write a little more on what you are trying to do and what exactly fails. – til_b Apr 16 '14 at 11:05
-
It is set inside of `php.ini`. The overall architecture is a simple php file that sets headers and echoes `json` string. – zogby Apr 16 '14 at 11:07
-
So you have a PHP script which outputs JSON, and the charset is wrong, despite having set a default charset in php.ini, and you only get the correct charset if you specify utf8 directly in the response header? – til_b Apr 16 '14 at 11:34
-
@til_b Absolutely correct – zogby Apr 16 '14 at 11:41
-
The answer to another question http://stackoverflow.com/a/9351983/2168905 says to also check for Apache default charset, and to make sure the PHP script file itself is stored as utf8. I am guessing it is the latter (PHP script file needs to be stored in utf8). – til_b Apr 16 '14 at 11:45
-
1None of that helps. Apache `AddDefaultCharset` is set to `utf-8`, PHP script is in `utf-8`. – zogby Apr 16 '14 at 13:10
-
1@til_b There is no reason to point out you are out of ideas. I have already said that adding `charset=utf-8` fixes the problem. I just do not understand why do I have to add it if a charset for an `application/json` is at least redundant! – zogby Apr 18 '14 at 10:20