如何去除反斜杠在json_en code()函数? [英] How to remove backslash on json_encode() function?

查看:301
本文介绍了如何去除反斜杠在json_en code()函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何去除字符串中的(\)反斜线?在使用回声json_en code()

How to remove the (\)backslash on a string? when using echo json_encode() ?

例如:

<?php
$str = "$(\"#output\").append(\"<p>This is a test!</p>\")";

echo json_encode($str);
?>

请注意:当你回声$海峡,不会有问题......但是当你回声出使用 json_en code()(\)反斜线会显示出来。

note: When you echo $str, there will be no problem... but when you echo out using json_encode(), the (\)backslash will show up.

有没有办法解决呢?谢谢你。

Is there a way to solve this? Thank you.

推荐答案

为什么要? json_en code()只逃脱的东西需要转义的字符串,当你读它在你的JavaScript才能正常运行。当你执行JSON响应这将是转义自动。

Why would you want to? json_encode() only escapes things that need to be escaped for the string to work when you read it in your Javascript. It will be 'unescaped' automatically when you execute the JSON response.

这篇关于如何去除反斜杠在json_en code()函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆