美文网首页
中文转html utf-8 编码 (NODE-RED)

中文转html utf-8 编码 (NODE-RED)

作者: Songzh | 来源:发表于2020-10-22 21:57 被阅读0次

    node-red中中文转html utf-8 编码

    function ConvUtf8(obj) {
        return obj.replace(/[^\u0000-\u00FF]/g, function ($0) { return escape($0).replace(/(%u)(\w{4})/gi, "&#x$2;") });
    }
    msg.payload = ConvUtf8(msg.payload)
    return msg;
    
    

    案例:


    image.png
    [{"id":"92a538f0.2bc408","type":"function","z":"59a2a87e.f0abc8","name":"","func":"function ConvUtf8(obj) {\n\treturn obj.replace(/[^\\u0000-\\u00FF]/g, function ($0) { return escape($0).replace(/(%u)(\\w{4})/gi, \"&#x$2;\") });\n}\nmsg.payload = ConvUtf8(msg.payload)\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":340,"y":260,"wires":[["fbedad27.0b192"]]},{"id":"5dd9db22.161fc4","type":"inject","z":"59a2a87e.f0abc8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"玉子","payloadType":"str","x":160,"y":260,"wires":[["92a538f0.2bc408"]]},{"id":"fbedad27.0b192","type":"debug","z":"59a2a87e.f0abc8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":540,"y":260,"wires":[]}]
    

    相关文章

      网友评论

          本文标题:中文转html utf-8 编码 (NODE-RED)

          本文链接:https://www.haomeiwen.com/subject/wbzpmktx.html