gpt4 book ai didi

javascript - 如何使用ajax正确地将json发送到RestController?

转载 作者:行者123 更新时间:2023-11-28 18:27:26 26 4
gpt4 key购买 nike

我尝试将 json 发送到 api,但收到此错误:

com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'status': was expecting ('true', 'false' or 'null')

这是 JavaScript:

$("body").on('click','.btn-danger' ,(function (){
var id = $(this).val();
var data = {"status": "canceled",
"response": ""};
console.log(data);
$.ajax ({
type: 'PUT',
url: '/api/pendingrequests/' + id,
contentType: "application/json",
data: data,
dataType : "html"
}).done (function () {
$(this).hide();
});
}));

Controller :

@RequestMapping(value = "/api/pendingrequests/{requestId}", method = RequestMethod.PUT)
public ResponseEntity updateRequestStatus(@PathVariable Long requestId, @RequestBody HolidayRequestAction action) throws IOException {
return updateRequestStatusService.updateRequest(requestId, action);
}

以及我试图从请求中接收的 POJO:

public class HolidayRequestAction {
private String status;
private String response;

public String getStatus() {
return status;
}

public void setStatus(String status) {
this.status = status;
}

public String getResponse() {
return response;
}

public void setResponse(String response) {
this.response = response;
}
}

为什么我会收到此解析异常?可能是什么问题?

最佳答案

您的问题包含答案:'status': was expecting ('true', 'false' or 'null')

所以你不能发送其他值'true', 'false' or 'null'

但是请求中包含 "status": "canceled"

关于javascript - 如何使用ajax正确地将json发送到RestController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38853446/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com