找回密码
 免费注册

[PHP] 自定义json_decode函数解决Single unpaired UTF-16 surrogate in unicode escape

[复制链接]
admin 发表于 2024-1-6 18:18:34 | 显示全部楼层 |阅读模式
json_decode从有效的json字符串生成null结果,并显示错误"Single unpaired -16 surrogate in unicode escape“
  1. function custom_json_decode($json)
  2. {
  3.     $comment = false;
  4.     $out = '$x=';
  5.     for ($i=0; $i<strlen($json); $i++) {
  6.          if (!$comment) {
  7.              if (($json[$i] == '{') || ($json[$i] == '[')) $out .= ' array('; else if (($json[$i] == '}') || ($json[$i] == ']')) $out .= ')'; else if ($json[$i] == ':') $out .= '=>';
  8.     else
  9.     $out .= $json[$i];
  10.     }
  11.     else
  12.     $out .= $json[$i];
  13.     if ($json[$i] == '"' && $json[($i-1)]!="\")
  14.     $comment = !$comment;
  15.     }
  16.     eval($out . ';');
  17.     return $x;
  18. }

  19. custom_json_decode($data);
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 免费注册

本版积分规则

QQ|Archiver|手机版|小黑屋|信息共享网

GMT+8, 2024-5-14 10:25 , Processed in 0.064079 second(s), 18 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表