字符编码吧

GB2312:外国生产

GBK2312:中国生产

用百度开发平词法分析,必须把你发送的内容设置成GBK编码,但是返回的是string json类型,没法用json_decode()成功转化,通过json_last_error()得到错误代码5,通过json_last_error_msg().  一查文档说可能是字符编码不正确。

mb_detect_encoding()  输出字符串编码类型,结果是UTF-8,不应该啊,我在PHP文件一开始设置了

header("Content-type:text/html;charset=gbk2312");  那应该是gbk.

mb_convert_encoding($response."UTF-8","GB2312"); 结果json_decode() 可以转化成json了。


GBK2312:Chinese standard

GB2312:foreign standard

Today I user baidu Word parse to parse a sentence. But you must post data which is GBK encoding.

So according to his request. I get a string json which doesn't use json_decode() to transform.

The next I ues json_last_error() and json_last_error_msg() get code 5 . I find PHP manual to find cause.
The cause is UTF-8 encoding and it's not right.

mb_convert_encoding($response."UTF-8","GB2312"); finally the json_decode() is running well.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值