PHP去掉json字符串中的反斜杠及去掉双引号前的反斜杠_php实例

WBOY
Release: 2016-06-07 17:11:23
Original
882 people have browsed it

通过AJAX传到PHP的json字符串有时候加上反斜杠”\”来转义,PHP处理时需要先去掉反斜杠,然后再json_decode.

$str = stripslashes($_POST['json']); 
$arr = json_decode($str,true); 
Copy after login

PS:php get抓取json怎样去除双引号前面的反斜杠

你这个不算标准的JSON格式数据,可以先将\"替换成"即可。

再用json_decode()系统函数将其转为json对象,如需转为数组加上第二个参数为true即可。

若仍输出为NULL,是由于存在BOM头信息,

复制代码 代码如下:

$arr = json_decode(trim($json,chr(239).chr(187).chr(191)),true);

转换即可。

本文全部内容介绍完了,希望对大家在使用PHP去掉json字符串中的反斜杠\及去掉双引号前的反斜杠中有所帮助。

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