Home > Backend Development > PHP Tutorial > The json string variable obtained by php parsing http is always blank null, jsonnull_PHP tutorial

The json string variable obtained by php parsing http is always blank null, jsonnull_PHP tutorial

WBOY
Release: 2016-07-13 10:05:33
Original
1087 people have browsed it

The json string variable obtained by php parsing http is always blank and null, jsonnull

I encountered a problem in a colleague’s project today. The json string obtained through the http interface always uses json_decode Unable to parse correctly, returns blank.

Copy the result string directly and create a variable manually, but it works fine. It can also be parsed in the front-end js. I couldn’t figure it out for a long time. I solved the problem with the help of the powerful Google. The answer is that the result spit out by the interface contains a BOM header. The BOM header can be said to be the mortal enemy of PHP

No more talking, let’s go straight to the solution:

Copy code The code is as follows:
if (substr($return, 0,3) == pack("CCC",0xef,0xbb,0xbf)) {
$return = substr($return, 3);
}
$data = json_decode($return,true);

Record it here and share it with everyone. I hope it can be helpful to everyone.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/963118.htmlTechArticleThe json string variable obtained by php parsing http is always blank null, jsonnull Today, a colleague encountered a problem in the project, The json string obtained through the http interface is always incorrect using json_decode...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template