带有选项JSON_UNESCAPED_UNICODE的json_encode

时间:2021-02-11 00:26:39

When using echo json_encode($array, JSON_UNESCAPED_UNICODE);

当使用echo json_encode($ array,JSON_UNESCAPED_UNICODE);

I get the this error

我收到了这个错误

Warning: json_encode() expects exactly 1 parameter, 2 given

警告:json_encode()只需要1个参数,给定2个

2 个解决方案

#1


7  

Your php version might be too low:

你的php版本可能太低了:

http://php.net/manual/en/function.json-encode.php

http://php.net/manual/en/function.json-encode.php

string json_encode ( mixed $value [, int $options = 0 ] )

5.3.0    The options parameter was added

#2


4  

See patch at http://code.google.com/p/apns-php/issues/detail?id=22 which allows the same functionality on PHP 5.2.

请参阅http://code.google.com/p/apns-php/issues/detail?id=22上的补丁,它允许在PHP 5.2上使用相同的功能。

Basically run something like this:

基本上运行这样的事情:

foreach ($array as &$val) {
    $val = preg_replace_callback('/\\\\u([0-9a-f]{4})/i',
        function($matches) {
            return mb_convert_encoding(pack('H*', $matches[1]), 'UTF-8', 'UTF-16');
        }, $val);
}

#1


7  

Your php version might be too low:

你的php版本可能太低了:

http://php.net/manual/en/function.json-encode.php

http://php.net/manual/en/function.json-encode.php

string json_encode ( mixed $value [, int $options = 0 ] )

5.3.0    The options parameter was added

#2


4  

See patch at http://code.google.com/p/apns-php/issues/detail?id=22 which allows the same functionality on PHP 5.2.

请参阅http://code.google.com/p/apns-php/issues/detail?id=22上的补丁,它允许在PHP 5.2上使用相同的功能。

Basically run something like this:

基本上运行这样的事情:

foreach ($array as &$val) {
    $val = preg_replace_callback('/\\\\u([0-9a-f]{4})/i',
        function($matches) {
            return mb_convert_encoding(pack('H*', $matches[1]), 'UTF-8', 'UTF-16');
        }, $val);
}