This article mainly introduces the PHP parsing HTTP Get the JSON string variable is always a blank null solution, personal experience Summary, here recommended to everyone.
A problem has been encountered with today's colleague project that the JSON string obtained through the HTTP interface can always be parsed with json_decode, returning blank.
Copy the result string directly to create a variable is normal, in the front end JS can also be resolved, engaged in a half-day not its solution, with powerful Google solved the problem, the answer is the interface spit out the result contains a BOM header, BOM header this thing is the sworn enemy of Php Ah
Do not say, directly on the solution:
The code is as follows:
if (substr ($return, 0,3) = = Pack ("CCC", 0XEF,0XBB,0XBF)) {
$return = substr ($return, 3);
}
$data = Json_decode ($return, true);
Here to record, to share with you, hope to be able to help.