Search code examples
phpjsoniso-8859-1

How to get json_encode() to work with ISO-8859-1 (åäö)


json_encode() wont work for me when I'm using åäö. Why? And how can I get it to work?

The php:

echo json_encode($arr);

The javascript:

var theResponse = JSON.parse(xmlHttp.responseText);

When I alert() the response, and the response contains å, ä or ö, the response is = NULL

Please, help me out...


Solution

  • As Greg mentioned, I had to encode åäö to UTF-8. But I did't use iconv or mbstring. When I utf8_encode() all values before putting the values to the array the problem was solved.