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

[Android]WXStreamModule获取emoji表情问题 #1249

Closed
zjutkz opened this issue Sep 19, 2016 · 8 comments
Closed

[Android]WXStreamModule获取emoji表情问题 #1249

zjutkz opened this issue Sep 19, 2016 · 8 comments

Comments

@zjutkz
Copy link
Contributor

zjutkz commented Sep 19, 2016

如果通过stream去请求数据,type设置成json,并且后台接口返回的数据中包含emoji表情的话,emoji会解析失败,并且在特定情况下会造成json的解析失败。
原因是因为在WXStreamModule的fetch方法中,当走到成功的回调以后,会调用readAsString方法去将byte数组转换成String:
String respData = readAsString(response.originalData, headers!=null?headers.get("Content-Type"):"" );
在转化的过程中emoji是无法解析的,这是第一个问题。
第二问题是在特定情况下偶发的,如果这个emoji是位于字符串的最后一个位置,那么在byte[]转化成String的过程中,后引号会丢失,就像这样:
后台下发的是"xxxxxxxxx😄",通过byte[]换成成String之后,变成了"xxxxxxxxxxxo쌩Ģ,可以看到后引号丢失了。
所以我的建议是
resp.put("data",options.getType() != Options.Type.text? JSONObject.parse(respData):respData);
在转化成json的时候,入参不要是String,fastJson提供了入参是byte[]的方法,直接用比较合适。
至于转换成String之后emoji丢失的情况。。。貌似没什么好的办法。

@sospartan
Copy link
Contributor

@zjutkz 欢迎来提交对应的PR
@YorkShen 目前text也还不支持emoji吧

@YorkShen
Copy link
Contributor

weex android目前不支持emoji,会crash。 @zjutkz

@zjutkz
Copy link
Contributor Author

zjutkz commented Sep 19, 2016

@YorkShen 你的意思是即使能解析的出来,在对应的Text组件里使用了emoji就会crash吗?(没看过text组件的源码,不太清楚这方面的逻辑),如果是的话,之后会支持吗?

@YorkShen
Copy link
Contributor

Ref #350 @zjutkz

@zjutkz
Copy link
Contributor Author

zjutkz commented Sep 22, 2016

@YorkShen 关于emoji的问题,当我在通过stream.fetch去获取网络数据之后,在WXStreamModule的对应成功回调中打断点,发现得到的数据是这样的
可以看到emoji被转义了,而这样我正常的TextView中是可以显示的,但是当我把断点打到了WXBridgeManager的callNative方法中时,数据变成了这样
可以看到,emoji变成了其他奇怪的字符,而不是像之前一样转义的。
WXStreamModule的回调中正确,可以确定网络数据是没有问题的,但是WXBridgeManager的callNative方法中出了错,说明JSFramework层处理的时候把它变成了错误的东西,这个是v8的问题吗?还是其他什么原因?

@YorkShen
Copy link
Contributor

emoji不是modified UTF-8字符,Android NDK只支持Modified UTF-8,处理其他UTF-8字符,会出现异常现象。 https://developer.android.com/training/articles/perf-jni.html#UTF_8_and_UTF_16_strings @zavakid

@zjutkz
Copy link
Contributor Author

zjutkz commented Sep 22, 2016

@YorkShen OK,thanks

@YorkShen
Copy link
Contributor

参考这个commit, android 6.0 ndk不会crash,6.0以下的版本有可能crash。考虑使用byte[]数组进行数据通讯,绕过这个问题,参考这个提交,目前还没有验证64位系统和jni泄露 https://github.com/sospartan/weex/tree/android-bugfix-utf-8 。这个issue先关闭,进度跟踪 Ref #350 @zjutkz

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