假设您的saLoginResponse
类定义如下,并且您的strJSONEncode
字符串包含您在问题中发布的 JSON 数据,您的代码应该可以正常工作。
Public Class saLoginResponse
Public Property Result As String
Public Property UserID As String
Public Property Password As String
Public Property Locked As Boolean
Public Property Comment As String
Public Property LastLoggedOn As String
Public Property NumFailedAttempts As String
Public Property FirstName As String
Public Property LastName As String
Public Property MessageNum As String
Public Property MessageText As String
End Class
演示:
Sub Main()
Dim json As String = _
"{" + _
"""Result"":""Success""," + _
"""UserID"":""johns""," + _
"""Password"":null," + _
"""Locked"":""False""," + _
"""Comment"":""""," + _
"""LastLoggedOn"":""11/9/2013 9:14:17 PM""," + _
"""NumFailedAttempts"":""1""," + _
"""FirstName"":""John""," + _
"""LastName"":""Smith""," + _
"""MessageNum"":""UA-000""," + _
"""MessageText"":""Authorisation successful""" + _
"}"
Dim a As saLoginResponse = JsonConvert.DeserializeObject(Of saLoginResponse)(json)
Debug.WriteLine(a.MessageText + " for " + a.FirstName + " " + a.LastName)
End Sub
调试窗口中的输出:
Authorisation successful for John Smith