我在ajax请求的时候后端返回数据是return json($data)时,报错:Malformed UTF-8 characters, possibly incorrectly encoded。

原因:数组中存在非UTF-8的字符。

data为一个数组无法直接mb_convert_encoding。json_encode,base_encode都无法转换

解决方案:

/*** 数据中存在特殊字符无法直接json编码,先序列化字符* 再转码,转码后反序列化最后json编码*/// data为一个数组无法直接mb_convert_encoding。json_encode,base_encode都无法转换
$data = serialize($data);
$data = mb_convert_encoding($data, 'UTF-8', 'UTF-8,GBK,GB2312,BIG5' );
$data = unserialize($data);
return json($data);

到此文章就结束了,有什么疑问大家可以留言@我

thinkphp Malformed UTF-8 characters, possibly incorrectly encoded报错解决方案相关推荐

  1. PHP json_encode 返回 Malformed UTF-8 characters, possibly incorrectly encoded 问题

    Malformed UTF-8 characters, possibly incorrectly encoded 这个错误一般就是utf-8编码中有些特殊中文转码乱码导致的.重新转一次utf-8就好了 ...

  2. ts报错:Object is possibly ‘undefined‘.Vetur(2532)

    想要获得props中的数据,数据类型是number类型.但是却报错了Object is possibly 'undefined'. 按照报错提示,加断言改成props?.showDatasCount或 ...

  3. 【Logstash】windows下logstash报错config files contains non-ascii characters but are not UTF-8 encoded

    简介:启动报错·The following config files contains non-ascii characters but are not UTF-8 encoded 刚刚下载的logs ...

  4. requests模块报错:Use body.encode('utf-8') if you want to send it encoded in UTF-8.

    在做 企业向微信用户个人付款  功能时,调用第三方sdk,在 进行 requests 的post请求时, 代码如下 req = requests.post(url, data=data,cert(ap ...

  5. requests请求get接口报错UnicodeEncodeError: ‘latin-1‘ codec can‘t encode characters in position 13-14

    一.问题描述 在做接口自动化测试时,调用requests的get方法发送请求,报错,报错信息如下: Traceback (most recent call last):File "D:\D1 ...

  6. Android studio 报错解决:Error:SSL peer shut down incorrectly

    此文首发于我的Jekyll博客:zhang0peter的个人博客 很久没用 Android studio 了,刚刚在打开一个项目的biuld过程中报错: SSL peer shut down inco ...

  7. SAP MM在ML81N事务代码界面报错- Customizing incorrectly maintained –之对策

    SAP MM在ML81N事务代码界面报错- Customizing incorrectly maintained –之对策 笔者在很多项目的SAP系统里都遇到这个信息,在ML81N为服务采购订单创建s ...

  8. python3报错处理:UnicodeEncodeError: ‘ascii‘ codec can‘t encode characters in position 0-1

    一.背景说明 最开始不愿意使用Python,一大原因是因为Python2默认使用ASCII编码处理中文可以说是一件痛苦的事情.仅从更换默认编码一项变换,就可以说Python3和Python2不算同一门 ...

  9. 【转载】PHP报错分析(Corrupted encoded data detected in)

    一.执行PHP Zend加密文件报错 现象: 打开网站,出现以下错误 Fatal error: Unable to read **** bytes in 或者是 Fatal error: Corrup ...

  10. 'ascii' codec can't encode characters in position 20-24:ordinal not in range(128)报错根本解决办法

    转载地址:https://blog.csdn.net/Mickey220521/article/details/82759930 遇到这个问题,本人解决了一下午,亲测有效,可以解决根本问题. 讲一下背 ...

最新文章

  1. DATE_FORMAT() 函数||DATE_SUB() 函数
  2. pyinstaller打包pyqt文件(转)
  3. 关于主机的思维导图_读《思维导图》系列丛书----我用思维导图做什么?
  4. 延长汽车使用寿命,抛弃六大用车坏习惯
  5. OpenCV的imshow不能显示图像(显示的图像全灰)
  6. 一个使用Jmeter做接口性能测试的实战案例
  7. 图像分类数据集-09-p3
  8. php 获取 参数名和参数值,如何快速的获得url地址中参数名和参数值(在看PHP手册的时候无意间看见这两个函数,猜想能不能搭配使用。)...
  9. 【NOIP2001】【Luogu1049】装箱问题
  10. UVAlive3662 Another Minimum Spanning Tree 莫队算法
  11. 小程序中的大道理之二
  12. vscode中查看二进制文件
  13. 华为鸿蒙系统操作教程_华为鸿蒙操作系统入门到精通教程
  14. babel转码器的使用
  15. 实训4——RFID刷卡开锁
  16. DELL XPS 8930-R 从优盘安装centos7服务器
  17. ESP32 UART串口通信
  18. python中columns用法_pandas中DataFrame修改index、columns名的方法示例
  19. Linux系统发展历史
  20. 为什么要有SerialVersionUID?

热门文章

  1. 解决“the security certificate for this site has been revoked.the site should not be trusted.”
  2. 一文详解空洞卷积(Atrous Convolution)
  3. python实现的EDF(earliest deadline first)算法
  4. 2022年卫浴行业报告:套系化+智能化拓宽边际,箭牌家居内资领航
  5. excel 筛选重复项_列表项的Excel筛选器:2011年“鲨鱼周”
  6. 上传身份证照片js_web端上传图片,截取证件照
  7. 分割符(split)
  8. 浏览器的id_在浏览器的环境下学习ES6的模块化
  9. 05 pandas变形
  10. yolo数据集标注软件安装+使用流程