我有一个JavaFX应用程序和一个Java服务器,我试图用JSON发送一个post方法,但当我这样做时,我从服务器收到了这个错误
Resolved [org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Invalid UTF-8 middle byte 0x77; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Invalid UTF-8 middle byte 0x77
at [Source: (PushbackInputStream); line: 1, column: 209] (through reference chain: java.util.ArrayList[0]->pwsztar.edu.pl.project_kino.dto.Film["opis"])]
我的帖子请求看起来像这个
String json = new Gson().toJson(filmsToDelete);
System.out.println(json);
var request = new HttpPost("http://localhost:8080/api/v1/removeFilm");
request.setHeader("Content-type", "application/json;charset=UTF-8");
request.setEntity(new StringEntity(json));
HttpResponse response = client.execute(request);
System.out.println(response.getStatusLine());
filmToDelete
是Film
对象的数组列表。这是服务器上的矿井控制器方法
@PostMapping(path = "removeFilm")
public void removeFilms(@RequestBody ArrayList<Film> filmsToRemove){
filmService.printFilms(filmsToRemove);
}
所以我想知道的是问题在哪里,也许我该如何解决。如果有任何额外的信息让我知道
在StringEntity
:上设置正确的编码
request.setEntity(new StringEntity(json, "UTF-8"));