Open
Conversation
如用户信息某一字段存在特殊字符,这导致JSON_DECODE返回NULL,现对微信服务器请求结果进行编码替换后在进行解析。
Owner
|
微信中用户信息的地址也出现了特殊字符吗? 我目前还没有发现 |
Contributor
Author
|
有这种情况,我贴出的实例代码就是拉取到的一位用户的信息,而且这个CITY字段不同编码解析出来内容也不一样,导致JSON_DECODE无法解析。你把示例代码json直接用json_decode试一下就可以看出问题了 |
|
微信服务器会返回规定编码的字符串,我觉得特殊字符也会被微信端转换为UTF-8 ,所以目前应该无需考虑这个问题,之所以这里出现特殊字符,可能是楼主在浏览器直接访问接口时浏览器的编码为GBK或者GB18030,试着修改一下浏览器的默认编码为UTF-8 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
如用户信息某一字段存在特殊字符,这导致JSON_DECODE返回NULL,现对微信服务器请求结果进行编码替换后在进行解析。
示例代码:
$str = '{"subscribe":1,"openid":"o7TC3v_zvuxmuRPU6YeBOD6cz0Ng","nickname":"文文","sex":2,"language":"zh_CN","city":"S�Y4","province":"Q���Sä","country":"","headimgurl":"http://wx.qlogo.cn/mmopen/0dhrpQA7Vn64H2u2zApyiaicEg4hk0UCIqrJP0EcRDh1z108ARaaWUYIDfmLvBXicxGpo4uWej1PjsdMZcWIdPQ7TJehRnLWaJD/0","subscribe_time":1482894792,"remark":"","groupid":0,"tagid_list":[]}';
json_decode($str, true); 返回NULL 主要原因是city字段含有特殊符合或表情符号