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

Native端返回到JS端,中文乱码 #3

Closed
phoenixsky opened this issue Apr 8, 2021 · 2 comments
Closed

Native端返回到JS端,中文乱码 #3

phoenixsky opened this issue Apr 8, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@phoenixsky
Copy link

需要将native端返回的内容经过以下处理,中文才能正常显示

function decodeStr(str) {
    var out, i, len, c;
    var char2, char3;
    out = "";
    len = str.length;
    i = 0;
    while (i < len) {
        c = str.charCodeAt(i++);
        switch (c >> 4) {
            case 0:
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
            case 6:
            case 7:
                // 0xxxxxxx
                out += str.charAt(i - 1);
                break;
            case 12:
            case 13:
                // 110x xxxx 10xx xxxx
                char2 = str.charCodeAt(i++);
                out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
                break;
            case 14:
                // 1110 xxxx 10xx xxxx 10xx xxxx
                char2 = str.charCodeAt(i++);
                char3 = str.charCodeAt(i++);
                out += String.fromCharCode(((c & 0x0F) << 12) |
                    ((char2 & 0x3F) << 6) |
                    ((char3 & 0x3F) << 0));
                break;
        }
    }
    return out;
}
@phoenixsky
Copy link
Author

不知道和这个是否雷同
uknownothingsnow/JsBridge#21

@hcanyz hcanyz added the bug Something isn't working label Apr 8, 2021
hcanyz added a commit to hcanyz/ZJsBridge-ZJs that referenced this issue Apr 22, 2021
@hcanyz
Copy link
Owner

hcanyz commented Apr 22, 2021

@phoenixsky 浏览器提供的 atob 不支持解码 unicode。已换解码方式~

hcanyz added a commit that referenced this issue Apr 22, 2021
@hcanyz hcanyz closed this as completed Apr 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants