当前位置:   article > 正文

JSON parse error: Unexpected character (‘‘‘ (code 39)): was expecting double-quote to start ......_unexpected character (''' (code 39)): was expectin

unexpected character (''' (code 39)): was expecting double-quote to start fi

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对用双引号包裹。

如下所示.。

  1. $.ajax(
  2. {
  3. url:"testAjax",
  4. contentType:"application/json;charset=UTF-8",
  5. //正确的写法
  6. data:'{"username":"zs","password":"12456","age":"18"}',
  7. //错误的写法
  8. data:"{'username':'zs','password':'12456','age':'18'}",
  9. dataType:"json",
  10. type:"post",
  11. success:function (data) {
  12. // data是服务器端响应的数据
  13. alert(data);
  14. alert(data.username)
  15. }
  16. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/679580
推荐阅读
相关标签
  

闽ICP备14008679号