PHP接收前端ajax提交的json使用json_decode出現無法解析json的情況
前幾天跟公司前端對接接口的時候 , 前端傳入的json參數後臺無法解析 .
後來分析了一下之後 , 發現json字符串之中的部分特殊字符被html轉義了
解決方法 : 使用 html_entity_decode() 函數
$json = $_POST['json'];
$json = html_entity_decode($json); //**
$arr = json_decode($json);
html_entity_decode() 函數把 HTML 實體轉換爲字符 , 這樣就可以完美解決以上發現的問題