Home  >  Article  >  Backend Development  >  $results = json_decode($contents, true);返回null如何解决

$results = json_decode($contents, true);返回null如何解决

WBOY
WBOYOriginal
2016-06-06 20:15:371055browse

$results = json_decode($contents, true);返回null如何解决,看了微信那边返回的是utf-8字符编码的json,但是json_decode()返回error_code:4, error_msg:Syntax error;其实是一些看不见的字符,总不能每次把看不见的字符搂出来,一个个preg_replace()了,有没有通用的方法呢?网上搜了很多答案都解决不了。

回复内容:

$results = json_decode($contents, true);返回null如何解决,看了微信那边返回的是utf-8字符编码的json,但是json_decode()返回error_code:4, error_msg:Syntax error;其实是一些看不见的字符,总不能每次把看不见的字符搂出来,一个个preg_replace()了,有没有通用的方法呢?网上搜了很多答案都解决不了。

你不把不更的信息贴出来,谁能帮的了你呢?我做过微信公众号和企业号,好像没有这样的问题呢。json_decode本来就是处理utf-8字符集的。

results = json_decode($contents, true);
把$content 打印到一个log文件里 对比下 试试把日志的内容直接json_decode

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:composer Segmentation faultNext article:android 新手求教?