开发者

php json_decode something not display

I use php json_decode something from wikipedia, but something not display. I have added

header('Content-Type: text/html; charset=utf-8');

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

and

$data = json_decode(utf8_encode($body));

This miss thing is \/m\u02开发者_如何学Go59\u02c8d\u0292\u028cskju\u02d0lz\/


utf8_decode() does not look for string expressions like \u02c8. You have to decode it the other way round:

$data = json_decode($body, 1);  // first; converts \u1234 to strings

array_walk_recursive("utf8_decode_walk", $data);
function utf8_decode_walk($item, $key) {
    return utf8_decode($item);
}                               // replace UTF-8 with Latin-1

If it is a nested array, then you'll need array_walk_recursive with a wrapper function however.

Though if you send your output page with charset="UTF-8" anyway, you should not need the conversion step.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜