您的位置:首页 > Web前端 > JavaScript

js SyntaxError: JSON.parse: bad control character

2016-01-06 00:00 281 查看
firebug报错信息:SyntaxError: JSON.parse: bad control character in string literal at line 1 column 1903 of the JSON data

做了一个web项目,从后台返回一个JSONObject对象到jsp页面。接收对象在转换过程中报错。

后台代码:

DeliveryHttpInfo delivery = (DeliveryHttpInfo)map.get("deliveryHttpInfo") ;
request.setAttribute("deliveryInfo", JSONObject.fromObject(delivery)


jsp前台接收代码

<%@ 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

报错解决:要么删除特殊字符,要么代码替换特殊字符
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: