比如前台一个js object:
{
aa: "cc\dd"
}$d = '{\"aa\": \"cc\\dd\"}';
这时候用 json_decode($d, true) 会返回NULL, 如果用stripslashes 处理的话,斜杠都没了,会变成 aa: ccdd
怎么能支持带 \ 的decode。。谢谢。
{
aa: "cc\dd"
}$d = '{\"aa\": \"cc\\dd\"}';
这时候用 json_decode($d, true) 会返回NULL, 如果用stripslashes 处理的话,斜杠都没了,会变成 aa: ccdd
怎么能支持带 \ 的decode。。谢谢。
建议楼主在前台把"aa": "cc\dd" 改成"aa": "cc\\dd"
这样接受到的就是'{\"aa\": \"cc\\\\dd\"}'
然后可能要借助一个json类 网上下一个 代码太长 就不贴了
<?php
include('json.class.php');
$json_str ='{\"aa\": \"cc\\\\dd\"}';
$json = new MY_JSON();
$json_str = stripslashes($json_str);
var_dump($json->decode($json_str));//array
'aa' => string 'cc\dd' (length=5)
?>或者楼主可以选择在传递时对链接 encodeURI()进行编码
或者对内容encodeURIComponent()进行编码