zend-json
zend-json copied to clipboard
utf8 encoded error
there is a problem when json_encode get an incorrect character but i have a solution: in Json.php
private static function encodeViaPhpBuiltIn($valueToEncode, $prettyPrint = false)
{
if (! function_exists('json_encode') || static::$useBuiltinEncoderDecoder === true) {
return false;
}
$encodeOptions = JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP;
if ($prettyPrint) {
$encodeOptions |= JSON_PRETTY_PRINT;
}
array_walk_recursive($valueToEncode, function(&$item, $key){
if(!mb_detect_encoding($item, 'utf-8', true)){
$item = utf8_encode($item);
}
});
$encoded = json_encode($valueToEncode, $encodeOptions | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
return $encoded ? $encoded : json_last_error_msg();
}
The new section is from array_walk_recursive().
This repository has been closed and moved to laminas/laminas-json; a new issue has been opened at https://github.com/laminas/laminas-json/issues/2.