How to convert javascript unicode notation code to utf-8?

后端 未结 2 2041
失恋的感觉
失恋的感觉 2020-12-14 21:10

Is there a command line tool or online service that can convert javascript unicode notation code to utf-8?

E.g. I got this json code, but it is hard to edit in commo

相关标签:
2条回答
  • 2020-12-14 21:20
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"         "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
        <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
        <title>UTF-8 To Unicode</title>
        <style type="text/css">
        <!--
        td {
            height: 24px;
            line-height: 24px;
        }
        #content {
            margin-top: 2px;
        }
        -->
        </style>
        </head>
        <script type="text/javascript">
            function encodeGB2312(){
                var c = document.all.content.value;
                var re = /(%)+/g;
                var result =  escape(c);
                document.all.content.value =  result.replace(re, "\\");
                document.all.content.focus();
                document.all.content.select();
            }
            function clearContent(){
                document.all.content.value = "";
                document.all.content.focus();
            }
        </script>
    
        <body>
            <h3 align="center">UTF-8 To Unicode</h3>
            <table width="600" border="1" cellspacing="0" cellpadding="0" align="center"         style="text-align:center;">
              <tr>
                <td>Input what you want to convert:</td>
                <td><input type="text" name="content" id="content" size="50"/></td>
              </tr>
              <tr>
                <td colspan="2">
                <input type="button" name="encoding" value="Start Conversion"         onclick="encodeGB2312()"/>&nbsp;&nbsp;&nbsp;&nbsp;
                <input type="button" name="clear" value=" Cancel" onclick="clearContent();"/></td>
              </tr>
            </table>
        </body>
        </html>
    

    This is a sample of convert utf-8 to unicode, do it in turn.

    0 讨论(0)
  • 2020-12-14 21:35

    You use the below javascript function to convert unicode to utf-8

    function encode_utf8( s ){
        return unescape( encodeURIComponent( s ) );
    }( '\u4e0a\u6d77' )
    

    You can also try it out in firebug console. It works.

    0 讨论(0)
提交回复
热议问题