firebug報錯信息:SyntaxError: JSON.parse: bad control character in string literal at line 1 column 1903 of the JSON datajavascript
作了一個web項目,從後臺返回一個JSONObject對象到jsp頁面。接收對象在轉換過程當中報錯。html
後臺代碼:
java
DeliveryHttpInfo delivery = (DeliveryHttpInfo)map.get("deliveryHttpInfo") ; request.setAttribute("deliveryInfo", JSONObject.fromObject(delivery)
jsp前臺接收代碼web
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <% Object deliveryInfo = request.getAttribute("deliveryInfo"); %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>城市名定位</title> </head> <body> 123456 </body> </html> <script type="text/javascript"> $(document).ready(function () { var deliveryInfos = JSON.parse('<%=deliveryInfo%>'); //{"storeCode":"0551be67-03ff-40e7-8ef0-44ce288b1a09","storeContact":"\t 吳明琴","storeCustomerDistance":"0.178","storeCustomerTime":"\n"} ...... }); </script>
報錯緣由:deliveryInfo對象中包含特殊字符 \t \n
jsp
報錯解決:要麼刪除特殊字符,要麼代碼替換特殊字符
ui