douaonong7807 2019-01-28 19:40
浏览 71

无法使用TM符号解析json文件

I receive some generated json files and some files would contain the ™ symbol, if the file has that then json_decode won't work on it, when I print $data NULL will be printed. If I manually remove the symbol then I will see the data. I am using the below code and it will print out what is in the json file until it gets to the json file that has the ™ symbol

$json = file_get_contents($count . '.json');
$data = json_decode($json);
echo '<pre>';
var_dump($data);
echo '</pre>';

I have tried using urlencode and urldecodeand htmlspecialchars but they don't work either.

  • 写回答

1条回答 默认 最新

  • dousha7904 2019-01-28 19:48
    关注

    json_decode will only parse UTF-8 strings. If the file you are reading is not UTF-8 format it will fail.

    If you do not know the encoding of the file you will be reading, there are ways to convert the data to UTF-8 before parsing it as shown in this post:

    PHP: Convert any string to UTF-8 without knowing the original character set, or at least try

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大