[Solved] JSON parse error: Unexpected character (‘‘‘ (code 39)): was expecting double-quote to start ……

This problem is encountered in spring MVC and JSP simulating asynchronous requests of Ajax.

Complete error message:

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

Error reason: the format of JSON in the front-end Ajax request is incorrect. The outer part of the array should be wrapped in single quotation marks, and the inner key & amp; Value pairs are enclosed in double quotes.

As shown below.

           $.ajax(
                {
                    url:"testAjax",
                    contentType:"application/json;charset=UTF-8",
                    //Right
                    data:'{"username":"zs","password":"12456","age":"18"}',
                    //Wrong
                    data:"{'username':'zs','password':'12456','age':'18'}",
                    dataType:"json",
                    type:"post",
                    success:function (data) {
                    //    data is the server-side response data
                        alert(data);
                        alert(data.username)
                    }
                }

Read More: