json_decode产生错误“unicode escape中的单个未配对的UTF-16代理”并返回null

问题描述 投票:-1回答:1

json_decode从有效的json字符串生成null结果,错误“unicode escape中的单个未配对的UTF-16代理”

php json
1个回答
-2
投票

我用自定义json_decode函数解决了如下:

function custom_json_decode($json)
{
    $comment = false;
    $out = '$x=';
    for ($i=0; $i<strlen($json); $i++) {
         if (!$comment) {
             if (($json[$i] == '{') || ($json[$i] == '[')) $out .= ' array('; else if (($json[$i] == '}') || ($json[$i] == ']')) $out .= ')'; else if ($json[$i] == ':') $out .= '=>';
    else
    $out .= $json[$i];
    }
    else
    $out .= $json[$i];
    if ($json[$i] == '"' && $json[($i-1)]!="\\")
    $comment = !$comment;
    }
    eval($out . ';');
    return $x;
}

custom_json_decode($data);
© www.soinside.com 2019 - 2024. All rights reserved.