开发者

Using json_decode on a JSON feed containing Cyrillic characters

I'm trying to decode a JSON feed contain开发者_StackOverflow中文版ing 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?


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

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


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));


hermanschutte Use the escape function when sending data through javascript

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜