0
我有一個看起來像這樣一些JSON數據:JavaScriptSerializer無法解析的數據類型
{
"data":
[{
"name":"John Smith",
"id":"12345"
}]
}
我有像這樣一對可序列化類:
<Serializable()> _
Public Class User
Private _name As String
Private _id As String
Public Property name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
Public Property id() As String
Get
Return _id
End Get
Set(ByVal value As String)
_id = value
End Set
End Property
End Class
<Serializable()>
Public Class UserData
Private _data As List(Of User)
Public Property data() As List(Of User)
Get
Return (_data)
End Get
Set(ByVal value As List(Of User))
_data = value
End Set
End Property
End Class
當我嘗試反序列化作爲對象:
Dim serializer As New JavaScriptSerializer()
Dim userResult As Object = serializer.DeserializeObject(json)
我與關鍵「數據」,和價值2名兒童的另一個對象一個根對象,與關鍵s「name」和「id」,以及可能期望的適當值。但是,當我嘗試將該對象投射到我的UserData
類型時,它將返回Nothing
。我有這個代碼在某些時候工作,但現在我回到它並試圖再次使用它,似乎有一些代碼腐爛已經設置,並已停止工作。
這裏是我在嘗試獲得反序列化數據爲UserData
對象:
Dim userResult As UserData = TryCast(serializer.DeserializeObject(json), UserData)