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

存在中文乱码问题 #2

Closed
huagang opened this issue Apr 30, 2015 · 1 comment
Closed

存在中文乱码问题 #2

huagang opened this issue Apr 30, 2015 · 1 comment

Comments

@huagang
Copy link

huagang commented Apr 30, 2015

bridge.callHandler('showGoodsSearchResults', {'keyword': '感冒'}, function(response) {
})

'感冒' 会在Native会解析成u611Fu5192
,html端使用的utf-8编码
,这个问题您怎么看???

@huagang
Copy link
Author

huagang commented Apr 30, 2015

暂时解决了Native获取JS传中文参数乱码问题

把这个实现改了下:
webView.evaluateJavascript(script, new ValueCallback() {
@OverRide
public void onReceiveValue(String value) {
if(callback!=null) {
if(value != null && value.startsWith(""") && value.endsWith(""")) {

                      //获取JS 参数,JS中文参数用Unicode编码,这里进行转换
                     if(value.indexOf("\\u") == value.lastIndexOf("\\u")){
                         //加6,不解释
                         String Uvalue= value.substring(value.indexOf("\\u"),value.indexOf("\\u")+6);
                         value = value.replace(Uvalue,decode(Uvalue));
                     }else{
                         String Uvalue= value.substring(value.indexOf("\\u"),value.lastIndexOf("\\u")+6);
                         value = value.replace(Uvalue,decode(Uvalue));
                     }

                        value = value.substring(1,value.length()-1).replaceAll("\\\\", "");
                    }
                    callback.onReceiveValue(value);
                }
            }
        });

注:decode()方法是把Unicode字符转换成中文String方法

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

1 participant