javascript - 为什么读取二维码中的特殊字符时出现编码问题?
问题描述
我正在尝试读取 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);
}
});
}
解决方案
推荐阅读
- nginx - nginx 重写不起作用 - 返回 404
- python - 如何在不使用 scipy.optimize 拟合感兴趣的特征的情况下拟合函数?
- proxy - 通过 quickfix 连接到代理时出现异常
- python - 输入十进制命令?
- java - 与 google 即时游戏和 com.google.gms.google-services 插件冲突
- sql - 'nvarchar' 附近的语法不正确。必须声明标量变量“@Road”
- .net - Windows 应用程序丢弃所有 WCF 和 TCP 连接
- jboss - jboss 7.1,什么是standalone.log
- scala - 根据 Spark Scala 中的条件迭代和修剪字符串
- c - C程序在使用scanf获取用户输入时显示垃圾值