场景: 前端有时候会将JSON
对象用 JSON.stringify()
转成JSON
字符串后传递给后端,后端如果是PHP
写的话,使用 json_decode()
解析后,拿到的值是 NULL
解决方案:
将接收到的值,先用 html_entity_decode
处理后,再用 json_decode()
解析就可以了
$post_json = json_decode(html_entity_decode($post_data)); // $post_data 接受到的 JSON.stringify() 转换的json字符串