2

I'm trying to decode a JSON feed containing some Cyrillic characters. Not all of the characters in the feed is Cyrillic though. I'm using json_decode which works fine for anything else, but return garbage when there are Cyrillic characters.

The results look like this: Деффачки

Any ideas?

2
  • 1
    There are no cyrillic characters. There are certain encodings. You are trying to output utf-8 encoded text using single-byte encoding. Use utf-8 instead Commented Dec 24, 2010 at 18:46
  • Thanks for all the replies. Turns out adding "<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />" to the head of my page resolves the issue. Commented Dec 24, 2010 at 19:00

3 Answers 3

1

Your page is being decoded as CP1252 when it's actually UTF-8. Set your headers properly.

>>> print u'Деффачки'.encode('cp1252').decode('utf-8')
Деффачки
0
0

if you can not decode unicode characters with json_decode, use addslashes() while using json_encode. The problem comes from unicode chars starting with \ such as \u30d7

$json_data = addslashes(json_encode($unicode_string_or_array));

0

hermanschutte Use the escape function when sending data through javascript

Not the answer you're looking for? Browse other questions tagged or ask your own question.