Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emoji包含emoji表情的对象转化成json乱码 #49

Open
kevinke2012 opened this issue Aug 9, 2016 · 7 comments
Open

Emoji包含emoji表情的对象转化成json乱码 #49

kevinke2012 opened this issue Aug 9, 2016 · 7 comments

Comments

@kevinke2012
Copy link

这个框架最近使用了一下,发现个问题,如题,不知道咋解决,举个例子,该框架从数据库取出带emoji表情字段的对象,使用render转化返回给IOS客户端的时候,数据包乱码,导致IOS无法解析。
public void render(Object result) {
restResponse.originContent(result);
restResponse.write(toJson(result));
throw new RenderFinish();
}
之前使用springMVC的时候用的@responsebody注解是没有问题的,解析成json的动作SpringMVC代替了。也没有很多时间去研究他们的源码。
大神帮帮忙看一下

@allwefantasy
Copy link
Owner

和 @ ResponseBody 对等的是 render(200, 字符串对象, ViewType.string); 也就是我们渲染出去的就是原生的字符串。至于从数据库取出的对象如何转化成字符串,则需要你自己想办法解决。

@kevinke2012
Copy link
Author

qq 20160810114851
如图c为返回给客户端的String,正确的返回应该是\uD83D\uDE33,但是在用render(200, 字符串对象, ViewType.string);返回的时候变成乱码,猜测是\uD83D和\uDE33单独被解码了?

@allwefantasy
Copy link
Owner

恩,应该是被解码了。拿到后能否转义下?

@allwefantasy
Copy link
Owner

或者存储前做转义

@nudui
Copy link

nudui commented Nov 7, 2017

I`ve solved this problem,
just insert the following codes in JPA.java at method 'properties()'.
At all , please update your jetty version bigger than 7.

@nudui
Copy link

nudui commented Nov 7, 2017

    properties.put("initConnectionSqls","set names utf8mb4");

@nudui
Copy link

nudui commented Nov 7, 2017

DruidDataSourceFactory.java里的“config”方法,里面会获取property

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants