The problem that json strings cannot be parsed is that I made a PHP interface and the returned data is in json format (the data format is correct and the encoding is in utf8 format ); however, this json format data cannot be parsed during the call, but I can parse the returned data by copying it into a string. After searching for half a day, I found that there was a blank space in front of the output source code. However, this blank space cannot be solved through trim's space removal method, simulating the request interface, trim ($ result, "\ xEF \ xBB \ xBF") using the bom header; still cannot be resolved. Have you ever encountered this problem?
Reply to discussion (solution)
That is, if the json_encode output block is not written, whether the header is declared ('content-type: application/json; charset = utf-8 ');
It should be the impact of the BOM header.
$ Result = trim ($ result, "\ xEF \ xBB \ xBF ");
Only remove the BOM in $ result
The BOM of your php program file is not removed.
Create a new program
echo bin2hex(file_get_contents('http://yourhost/api.php'));
After j is executed, you can see whether BOM exists.
It should be the impact of the BOM header.
$ Result = trim ($ result, "\ xEF \ xBB \ xBF ");
Only remove the BOM in $ result
The BOM of your php program file is not removed.
Create a new program
echo bin2hex(file_get_contents('http://yourhost/api.php'));
After j is executed, you can see whether BOM exists.
It should be the impact of the BOM header.
$ Result = trim ($ result, "\ xEF \ xBB \ xBF ");
Only remove the BOM in $ result
The BOM of your php program file is not removed.
Create a new program
echo bin2hex(file_get_contents('http://yourhost/api.php'));
After j is executed, you can see whether BOM exists.
It should be the impact of the BOM header.
$ Result = trim ($ result, "\ xEF \ xBB \ xBF ");
Only remove the BOM in $ result
The BOM of your php program file is not removed.
Create a new program
echo bin2hex(file_get_contents('http://yourhost/api.php'));
After j is executed, you can see whether BOM exists.
We can see that these outputs are available at the frontend.
Bytes
How can I remove the bom header from the file?
First 2020 efbbbf
2020 indicates there are two spaces
Isn't efbbbf bom?
It should be the impact of the BOM header.
$ Result = trim ($ result, "\ xEF \ xBB \ xBF ");
Only remove the BOM in $ result
The BOM of your php program file is not removed.
Create a new program
echo bin2hex(file_get_contents('http://yourhost/api.php'));
After j is executed, you can see whether BOM exists.
Thanks for the enthusiastic answers from the moderator. The problem is finally solved. after checking all the relevant files, I found the file containing the bom header and edited it again to parse the json.
Notepad ++ converts a file to a non-BOM format.
You can see this log: http://my.oschina.net/rain21/blog/384549
Notepad ++ converts a file to a non-BOM format.
You can see this log: http://my.oschina.net/rain21/blog/384549
Thank you for your answers.