首页 > 解决方案 > 为什么读取二维码中的特殊字符时出现编码问题?

问题描述

我正在尝试读取 QR 码中的 JSON。问题是在阅读时,它一定有一些编码问题,并且它引入了奇怪的字符,而不是像重音、引号或符号这样的特殊字符。HTML 中的字符集已定义为 UTF-8。

二维码的 JSON:

{"status":2,"ts":1601999,"t_next_req":"3600","id":"ES0099","fullname":"José Manuel Cabo Martínez"}

JSON 我正在阅读:

ç000026^¨status¨Ñ¨2¨,¨ts¨Ñ1601999,¨t?next?req¨Ñ¨3600¨,ïd¨ÑËS0099¨,¨fullname¨Ñ¨José Manuel Cabo Martínez¨*

Javascript:

$(document).ready(function() {
var barcode="";
$(document).keypress(function(e) {
    var code = (e.keyCode ? e.keyCode : e.which);
    //Check that the QR code has been read
    if(code==13) {
        wait = true;
        console.log(barcode);
    } else {
        barcode = barcode + String.fromCharCode(e.which);
    }
});
}

标签: javascripthtmljqueryqr-codebarcode-scanner

解决方案


推荐阅读