为了账号安全,请及时绑定邮箱和手机立即绑定

中文乱码了

我把中文生成二维码的时候乱码了,我页面上是utf-8模式

正在回答

2 回答

解决中文乱码问题:
function utf16to8(str) {  
    var out, i, len, c;  
    out = "";  
    len = str.length;  
    for(i = 0; i < len; i++) {  
    c = str.charCodeAt(i);  
    if ((c >= 0x0001) && (c <= 0x007F)) {  
        out += str.charAt(i);  
    } else if (c > 0x07FF) {  
        out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));  
        out += String.fromCharCode(0x80 | ((c >>  6) & 0x3F));  
        out += String.fromCharCode(0x80 | ((c >>  0) & 0x3F));  
    } else {  
        out += String.fromCharCode(0xC0 | ((c >>  6) & 0x1F));  
        out += String.fromCharCode(0x80 | ((c >>  0) & 0x3F));  
    }  
    }  
    return out;  
}


0 回复 有任何疑惑可以回复我~

第一种方式不会出现中文乱码

第二种方式修改一下代码即可:byte[] d = qrData.getBytes("utf-8");

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
Java生成二维码
  • 参与学习       84406    人
  • 解答问题       203    个

二维码无处不在,自己动手用Java生成二维码,三种生成方式任你选

进入课程

中文乱码了

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信