【前端】WebSocket接收二进制数据转JSON并解决中文乱码问题(ArrayBuffer转json)
场景:
WebSocket与mqtt服务器通信,接收二进制数据并将其转为Json使用。一般方式都会出现中文乱码问题。
解决方法:
handleBinaryToJson(e) { let enc = new TextDecoder("utf-8"); let uint8_msg = new Uint8Array(e); let temp = enc.decode(uint8_msg) let res = JSON.parse(temp) console.log('res',res); },
文章版权声明:除非注明,否则均为主机测评原创文章,转载或复制请以超链接形式并注明出处。
还没有评论,来说两句吧...