如何在 .net 中转义 html unicode?
在网页中,我收到文本 \u30ca\u30bf\u30ea\u30a2。应该翻译成ナタaria。我只是不知道如何在.NET 中做到这一点。我尝试了 HttpUtility.HtmlDecode,当失败时我尝试了 HttpUtility.UrlDecode。没有运气
In a webpage i got the text \u30ca\u30bf\u30ea\u30a2. It should translate to ナタリア. I just dont know how to do it in .NET. I tried HttpUtility.HtmlDecode and when that failed i tried HttpUtility.UrlDecode. No luck
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,如果您的字符串是转义的,您将需要手动将字符串转换为 unicode ..或者我有更好的方法。 JSON 接受转义的 Unicode 字符并将其转换为普通字符,因此请尝试此操作(JavaScriptSerializer 位于
System.Web.Extensions.dll
中的System.Web.Script.Serialization
中):输出为:
And if you still want to do it manually n code . this answer with code on SO is what you want:
将 Unicode 字符串转换为转义 ASCII 字符串
I不想太相信发布他的代码。
Ok if your string is Escaped you will need to convert the string manually in to unicode.. or i have a better way. JSON accepts the Escaped Unicode chars and Convert it to normal chars so try this (The JavaScriptSerializer is in
System.Web.Script.Serialization
inSystem.Web.Extensions.dll
):and the output is :
And if you still want to do it manually n code . this answer with code on SO is what you want:
Convert a Unicode string to an escaped ASCII string
I don't want too take credit of posting his code.