如何解码javascript的编码字符串

时间:2014-12-16 23:44:05

标签: javascript c# html encoding decode

这是用于javascript函数的编码HTML代码

<div class=\"ProductDetail\"><div style=\"width:780px\">\r\n\t<div class=\"baslik\" style=\"margin: 0px; padding: 5px 10px; border-width: 5px 0px 1px; border-top-style: solid; border-bottom-style: solid; border-top-color: rgb(255, 255, 255); border-bottom-color: rgb(153, 165, 165); vertical-align: baseline; color: rgb(0, 0, 0); clear: both; line-height: 14px; font-family: 'Lucida Grande', sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(219, 223, 226);\">    Di\u011fer \u00d6zellikler<\/div><\/div><\/div>

正确解码后会变为

<div class="ProductDetail"><div style="width:780px">
<div class="baslik" style="margin: 0px; padding: 5px 10px; border-width: 5px 0px 1px; border-top-style: solid; border-bottom-style: solid; border-top-color: rgb(255, 255, 255); border-bottom-color: rgb(153, 165, 165); vertical-align: baseline; color: rgb(0, 0, 0); clear: both; line-height: 14px; font-family: 'Lucida Grande', sans-serif; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(219, 223, 226);">    Diğer Özellikler</div></div></div>

该网站具有解码和编码功能

http://www.freeformatter.com/javascript-escape.html#ad-output

我可以在c#找到HttpUtility.JavaScriptStringEncode但是我找不到任何函数类等来解码编码的字符串

所以我需要有关如何像该网站一样进行解码的帮助

.net 4.5 c#

3 个答案:

答案 0 :(得分:3)

哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇

然而,许多经验丰富的开发人员投票支持我之前的帖子:D

单行并且完美无缺

Regex.Unescape(string);

答案 1 :(得分:1)

你有没有尝试过:

        var unescapedString = Microsoft.JScript.GlobalObject.unescape(yourEscapedString);
        var escapedString = Microsoft.JScript.GlobalObject.escape(yourUnescapedString);

您应该为项目添加Microsoft.JScript引用。

答案 2 :(得分:0)

显示的编码足以构成JavaScript文字。这不需要任何额外的解码,因为解释器会为你做这件事。