赞
踩
在springmvc和jsp模拟ajax的异步请求中遇到这个问题。
完整的错误信息:
JSON parse error: Unexpected character (''' (code 39)): was expecting double-quote to start field name; nested exception is com.fasterxml.jackson.core.JsonParseException: Unexpected character (''' (code 39)): was expecting double-quote to start field name
错误原因:前端ajax请求中json的格式不对。数组的外围应该是单引号包裹,内部的key&value对用双引号包裹。
如下所示.。
- $.ajax(
- {
- url:"testAjax",
- contentType:"application/json;charset=UTF-8",
- //正确的写法
- data:'{"username":"zs","password":"12456","age":"18"}',
- //错误的写法
- data:"{'username':'zs','password':'12456','age':'18'}",
- dataType:"json",
- type:"post",
- success:function (data) {
- // data是服务器端响应的数据
- alert(data);
- alert(data.username)
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。