我需要將以下內容轉換爲VB.Net。我嘗試在線轉換器和轉換給出錯誤什麼是以下的VB.Net equavilent
var result = JsonConvert.DeserializeObject<T>(parsed["result"].ToString(),
new JsonSerializerSettings
{
/*
* Because Aliexpress Api logic is very weird -
* it could return "-" for totalResults field,
* Which is Integer by documentation and common sense
*/
Error = HandleDeserializationError
});
protected void HandleDeserializationError(object sender, ErrorEventArgs errorArgs)
{
var currentError = errorArgs.ErrorContext.Error.Message;
errorArgs.ErrorContext.Handled = true;
}
轉換後的代碼給出
Dim result = JsonConvert.DeserializeObject(Of T)(parsed("result").ToString(), New JsonSerializerSettings() With { _
Key .[Error] = HandleDeserializationError _
})
Protected Sub HandleDeserializationError(sender As Object, errorArgs As ErrorEventArgs)
Dim currentError = errorArgs.ErrorContext.[Error].Message
errorArgs.ErrorContext.Handled = True
End Sub
的ErrorEventArgs類定義爲
Public Class ErrorEventArgs
Inherits EventArgs
Public Sub New(currentObject As Object, errorContext As ErrorContext)
Public ReadOnly Property CurrentObject As Object
Public ReadOnly Property ErrorContext As ErrorContext
End Class
基本上我有轉換後的過程:
Protected Sub HandleDeserializationError(sender As Object, errorArgs As ErrorEventArgs)
Dim currentError As String = errorArgs.ErrorContext.[Error].Message
errorArgs.ErrorContext.Handled = True
End Sub
,我需要把它分配爲事件處理
喜歡的東西
Dim s As JsonSerializerSettings = New JsonSerializerSettings()
s.Error = HandleDeserializationError()
Dim result = JsonConvert.DeserializeObject(Of T)(parsed("result").ToString(), s)
和錯誤消息? –
ErrorContext類的一部分 – Eminem
更新了描述 – Eminem