表情符号未正确编码以用于输出编写器 [英] Emoji are not being encoded correctly for output writer

查看:169
本文介绍了表情符号未正确编码以用于输出编写器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

程序吸收注释并将其保留.数据库正确存储了值.(我能够将其复制并粘贴到表情符号页面中,并且可以正确显示).我在调试器中对postComment请求和getAllComments响应看到的字符串是相同的,但是它正在发送{0xED,0xA0、0xBD,0xED,0xB8、0x80}而不是{0xF0、0x9F,0x98、0x80},最多显示几个字符,而不是1个字符.如果我将编码设置为UnicodeBig,则表情符号会显示在响应中,但我们需要使用UTF-8

The program takes in a comment and persists it. The database stores the value correctly.( i'm able to copy and paste it into an emoji page and it shows up correctly). The string i see in the debugger on the postComment request and in the getAllComments response is the same, but it is sending {0xED, 0xA0, 0xBD, 0xED, 0xB8, 0x80 } instead of { 0xF0, 0x9F, 0x98, 0x80 } and showing up as several characters instead of 1. If i set the encoding to UnicodeBig the emoji show up in the response, but we need to be using UTF-8

String jsonString = jsonMapper.toJson(jsonResponse);
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.getWriter().println(jsonString);

在将系统编码为utf8之前,我是否需要对这些字符串进行处理? 使用的库是

Do i need to do something to these strings before having the system encode to utf8? the libs used are

json-simple-1.1(当前为1.1.1) jackson-core-2.2.3(当前2.6)

json-simple-1.1(current is 1.1.1) jackson-core-2.2.3(current 2.6)

谢谢.

推荐答案

这最终是Jetty 7的一个问题.要解决此问题,您只需.getBytes(String),然后将字节写出并刷新缓冲区即可. Java将获取正确的字节,并且不对代理对进行编码,这是Jetty默认情况下所做的.

This ended up being an issue with Jetty 7. to get around this you can just .getBytes(String) and then write the bytes out and flush the buffer. Java will get the correct bytes and not encode the surrogate pair which is what Jetty was doing by default.

这篇关于表情符号未正确编码以用于输出编写器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆