echo $res=addslashes(json_encode(array('content'=>'中文')));
//{\"content\":\"\\u4e2d\\u6587\"}
echo stripcslashes($res);//{"content":"\u4e2d\u6587"}
直接echo stripcslashes( '{\"content\":\"\\u4e2d\\u6587\"}');//{"content":"u4e2du6587"}
\不见了???不能用json_decode()解码了
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
JSON在编码的时候已经转义了,addslashes和stripcslashes都是多此一举。
字符串直接写入表示的是正常的转义. 话说encode完的不就可以直接decode么,为什么还要做这种多余的动作……