问题
通过SpringBoot 接收远程服务器推送的数据(json字符串),传递的字符串参数中文乱码,英文、数字显示正常,中文全部显示为‘?’号。
解决
对方发送的编码方式为UTF-8,所以接收数据的时候也设置编码格式,在springboot中可以通过@RequestMapping注解的produces参数进行设置,如下:
@RequestMapping(value = "/receiveData", method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = {"application/json; charset=UTF-8"})
public Map receiveData(@RequestBody String jsonStr) {
// ...
}