Home > Backend Development > PHP Problem > What should I do if php json cannot be parsed?

What should I do if php json cannot be parsed?

藏色散人
Release: 2023-03-08 10:32:02
Original
2103 people have browsed it

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.

What should I do if php json cannot be parsed?

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!

Related labels:
php
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