我如何在.net中转义html unicode?

时间:2011-02-14 00:06:28

标签: c# .net html escaping decode

在网页上我得到了文字\ u30ca \ u30bf \ u30ea \ u30a2。它应该翻译成ナタリア。我只是不知道如何在.NET中做到这一点。我尝试了HttpUtility.HtmlDecode,当失败时我尝试了HttpUtility.UrlDecode。没有运气

1 个答案:

答案 0 :(得分:2)

好的,如果您的字符串是Escaped,您需要手动将字符串转换为unicode ..或者我有更好的方法。 JSON接受Escaped Unicode字符并将其转换为普通字符,所以试试这个(System.Web.Script.Serialization位于System.Web.Extensions.dll中的string d = @"\u30ca\u30bf\u30ea\u30a2"; Console.WriteLine("Unicode Escaped:" + d); JavaScriptSerializer jr = new JavaScriptSerializer(); string dt = jr.Deserialize<string>("\"" + d + "\""); Console.WriteLine("Converted:" + dt); ):

Unicode Escaped: \u30ca\u30bf\u30ea\u30a2

Converted: ナタリア

,输出为:

{{1}}

<小时/> 如果你仍然想手动n代码。有关SO的代码的答案就是你想要的:

JavaScriptSerializer

我也不想过分发布他的代码。