法语口音给出“????>”在使用正确的Charset(Java)的HTTP响应中

发布于 2025-01-18 17:37:46 字数 947 浏览 3 评论 0原文

调用返回法语句子的 API,即使字符集定义良好(application/json;charset=iso-8859- 1)。

使用邮递员或我的网络浏览器,我没有遇到任何问题。 我还尝试使用 Content-Type 标头调用 API,标头的值为 application/json;charset=UTF-8application/json;charset=iso -8859-1 但问题仍然相同。 有什么想法吗?

response.getBody() 给出:

{"sentences":[{"fr_value":"il �tait loin","dz_value":"kaan b3id","additional_information":{"personal_prounoun":"HE","verb":"�tre","adjective":"loin","tense":"pass�"}}],"count":1}

new String(response.getBody().getBytes(StandardCharsets.UTF_8)) 给出完全相同的结果。

输入图片此处描述

我正在使用 scribejava。

编辑:即使将响应保存在文件中并使用 NotePad++ 打开它,结果也类似: 输入图片此处描述

Calling an API that returns french sentences, all the accented characters are displayed like <?> in my java code, even if the charset is well defined (application/json;charset=iso-8859-1).

Using postman or my web browser, I don't face any problem.
I also tried to call the API with a Content-Type header with the value application/json;charset=UTF-8 or application/json;charset=iso-8859-1 but the problem remains the same.
Any idea ?

response.getBody() gives:

{"sentences":[{"fr_value":"il �tait loin","dz_value":"kaan b3id","additional_information":{"personal_prounoun":"HE","verb":"�tre","adjective":"loin","tense":"pass�"}}],"count":1}

new String(response.getBody().getBytes(StandardCharsets.UTF_8)) gives exactly the same.

enter image description here

I'm using scribejava.

Edit: even saving the response in a file and opening it with NotePad++, the result is similar:
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

东京女 2025-01-25 17:37:46

您需要将其阅读为ISO-8859-1。不知道那是什么,因为我不知道你在做什么。我的 https://technojeeves.com/indexnojeeves.com/index.php/alliasjava1/51/51/51/51/51 - transcode in-java 很有帮助。与WGET:
WGET -O- us-central1-dz-dialect-api.cl…| xcode -ie latin1(我制作了'xcode'来调用该Java应用程序)

You need to read it as ISO-8859-1. Not sure what then as I don't know what you're doing. My https://technojeeves.com/index.php/aliasjava1/51-transcode-in-java is helpful. With wget:
wget -O - us-central1-dz-dialect-api.cl… | xcode -ie Latin1 (I made 'xcode' to invoke that Java app)

拥抱没勇气 2025-01-25 17:37:46

使用以下代码解决的问题:

      httpResponse.setContentType("application/json;charset=UTF-8");
      mapper.getFactory().configure(JsonGenerator.Feature.ESCAPE_NON_ASCII, true);

Problem solved using the following code :

      httpResponse.setContentType("application/json;charset=UTF-8");
      mapper.getFactory().configure(JsonGenerator.Feature.ESCAPE_NON_ASCII, true);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文