mqtt订阅的输出发现有些参数值是乱码,经过反馈是gbk2312,网上查找了许多转义方法,都没效果?
mqttClient.on( 'message' , (topic, message) => { // message is Buffer message = JSON.parse(message.toString()); console.log( '收到来自:' , topic, '的消息:' , message); // console.log(topic, ', 收到消息:', JSON.parse(iconv.decode(message, 'gb2312'))); console.log(message.term.profName); if ( this .mqttMsgReadyCallback) { // 全局回调发送消息 this .mqttMsgReadyCallback(topic, message) }; }); |