天天看點

解決php中json_decode的異常JSON_ERROR_CTRL_CHAR (json_last_error = 3)

https://www.cnblogs.com/sanshuiqing/p/6022619.html

解決php中json_decode的異常JSON_ERROR_CTRL_CHAR (json_last_error = 3)

該字元中含了ASCII碼ETB控制符,即\x17導緻json解析失敗 (截圖中顯示ETB是因為用了Sublime text2)

解決方法如下:去掉0-31的控制符再進行decode

$result = "json格式字元串如圖";
$result = preg_replace('/[\x00-\x1F]/','', $result);
$result = json_decode($result);