Javascript解碼格式的字符串

形如以下格式的字符串,中文是以&#x加四位十六進制數字的UTF-8編碼:

System.Runtime.InteropServices.COMException (0x80041FEC): 异常来自 HRESULT:0x80041FEC
   在 Microsoft.Internal.VisualStudio.Shell.Interop.IVsSolutionBuildOrderPrivate.GetBuildOrderList(Boolean fForceRecalculation, UInt32 cProjects, VsProjectBuildOrder[] pBuildOrder, UInt32& pValidationId)
   在 Microsoft.VisualStudio.ErrorListPkg.Shims.TaskListBase.RecalculateProjectRank()
   在 Microsoft.VisualStudio.ErrorListPkg.Shims.TaskListBase.OnEntriesChanged(Object sender, EntriesChangedEventArgs e)
   在 Microsoft.VisualStudio.Text.Utilities.GuardedOperations.RaiseEvent[TArgs](Object sender, EventHandler`1 eventHandlers, TArgs args)
--- 引发异常的上一位置中堆栈跟踪的末尾 ---
   在 Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)

以上字符可以通過以下兩種方法解碼:

1:

var encodeStr ='要解碼的內容';
var resultStr = eval('"' + encodeStr.replace(/&#x(.{4});/g,"\\u$1") + '"');

2:

var encodeStr ='要解碼的內容';
var resultStr = unescape(encodeStr.replace(/&#x(.{4});/g,"%u\$1"));

另外,站長之家也有提供解碼工具,地址是:http://tool.chinaz.com/tools/utf-8.aspx,進入之後將編碼內容粘貼到右邊的文本框裏,單擊“UTF-8轉中文”按鈕即可得到解碼後的內容。

 

上面那段文字解碼後爲:

System.Runtime.InteropServices.COMException (0x80041FEC): 異常來自 HRESULT:0x80041FEC
   在 Microsoft.Internal.VisualStudio.Shell.Interop.IVsSolutionBuildOrderPrivate.GetBuildOrderList(Boolean fForceRecalculation, UInt32 cProjects, VsProjectBuildOrder[] pBuildOrder, UInt32& pValidationId)
   在 Microsoft.VisualStudio.ErrorListPkg.Shims.TaskListBase.RecalculateProjectRank()
   在 Microsoft.VisualStudio.ErrorListPkg.Shims.TaskListBase.OnEntriesChanged(Object sender, EntriesChangedEventArgs e)
   在 Microsoft.VisualStudio.Text.Utilities.GuardedOperations.RaiseEvent[TArgs](Object sender, EventHandler`1 eventHandlers, TArgs args)
--- 引發異常的上一位置中堆棧跟蹤的末尾 ---
   在 Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章