The solution to the problem that php json cannot be parsed: first switch to the corresponding project directory; then search for the file containing the BOM header and clear the BOM header command under Linux and execute the relevant commands.
The operating environment of this article: linux5.9.8 system, PHP7.1 version, DELL G3 computer
PHP interface returns json string When debugging an interface in the past two days, the local test was normal, and the postman test was also normal. However, when it was provided to the partner, they said it could not be parsed normally. After many twists and turns, Finally, it was found that the json string contained a \ufeff in front of it,
The specific reason: changing the UTF-8 format encoding to UTF-8 BOM-less format encoding caused the json string to not be parsed normally.Solution:
linux server: Switch to the corresponding project directory:
Find the file containing the BOM header and clear the BOM header command under Linux (1). Execute: grep -r -I -l $'^\xEF\xBB\xBF' ./ Find files containing bom (2). Execute: find. -type f -exec sed -i 's/\xEF\xBB\xBF//' {} \; Remove all bom[Recommended learning: "PHP Video Tutorial
"]The above is the detailed content of What should I do if php json cannot be parsed?. For more information, please follow other related articles on the PHP Chinese website!