报错信息:
JSON parse error: Unrecognized token ‘username’: was expecting (‘true’, ‘false’ or ‘null’); nested exception is com.fasterxml.jackson.core.JsonParseException: Unrecognized token ‘username’: was expecting (‘true’, ‘false’ or ‘null’) at [Source: (PushbackInputStream); line: 1, column: 10]]
报错原因:
这是由于请求的json数据的格式有问题
原数据格式:{“username”:“张三”,“age”:20,“address”:“深圳”}
解决方法:
使用 JSON.stringify(data)这个函数,该函数会将动态的Object转成静态json String。
修改后格式:
JSON.stringify({“username”:“张三”,“age”:20,“address”:“深圳”})