課程
/后端開發(fā)
/Java
/Java生成二維碼
我自己寫的中文無論怎么改為啥都是亂碼呢?請問各路大牛
2017-05-09
源自:Java生成二維碼 6-4
正在回答
在二維碼編碼前把字符串轉(zhuǎn)換成UTF-8
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));
}
? ? }
? ? return out;
舉報
二維碼無處不在,自己動手用Java生成二維碼,三種生成方式任你選
1 回答中文會亂碼 怎么解決呀?
2 回答中文的亂碼
5 回答VCard中文亂碼
2 回答中文亂碼了
3 回答二維碼內(nèi)容是中文時輸出亂碼
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2017-05-10
在二維碼編碼前把字符串轉(zhuǎn)換成UTF-8
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;
}