spring 俄语字符在java中显示为???

qyswt5oh  于 2023-04-10  发布在  Spring
关注(0)|答案(2)|浏览(66)

我有一个控制器,它必须返回一个带有俄语名称的JSON字符串,但我得到的响应是????(无效字符)。

@Controller
public class ManifestController {

    @ResponseBody
    @RequestMapping(value = {"/manifest.json","/manifest"}, method = { RequestMethod.GET }, produces = {MediaType.APPLICATION_JSON_VALUE})

    public String getManifestJson(
            HttpServletRequest request)
    {
        Employee e= new Employee ();
        e.setName("Мегафон Игры"); 

        return JsonUtil.jsonStringify(e);  //it converts object to json using JsonObjectMapper

    }
}
vom3gejh

vom3gejh1#

我在我的机器上试过了,它工作了

User e = new User();
  e.setFirstName("Мегафон Игры");
  ObjectWriter ow = new ObjectMapper().writer().withDefaultPrettyPrinter();
  String json;
  json = ow.writeValueAsString(e);
  return json;

我收到的:

{
"id": 0,
"creationDate": null,
"username": null,
"firstName": "Мегафон Игры",
"lastName": null,
"email": null,
"updateDate": null,
"active": 0
}
olmpazwi

olmpazwi2#

它帮助我在响应头中设置编码:

response.setCharacterEncoding("UTF-8");

相关问题