且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

jersey web 服务 json utf-8 编码

更新时间:2023-11-27 12:05:22

默认情况下,Jersey 应该始终生成 utf-8,听起来问题是您的客户端没有正确解释它(xml 声明不会使" 它是 utf-8,只是告诉客户端如何解析它).

Jersey should always produce utf-8 by default, sounds like the problem is that your client isn't interpreting it correctly (the xml declaration doesn't "make" it utf-8, just tells the client how to parse it).

您发现这些问题的客户是什么?

What client are you seeing these problems with?

有效的 JSON 应该只是 Unicode (utf-8/16/32);解析器应该能够自动检测到编码(当然有些不会),所以 JSON 中没有编码声明.

Valid JSON is only supposed to be Unicode (utf-8/16/32); parsers should be able to detect the encoding automatically (of course, some don't), so there is no encoding declaration in JSON.

您可以像这样将它添加到 Content-Type 中:

You can add it to the Content-Type like so:

@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")