将JSON字符串(无根)反序列化为对象VB.NET



I,

我需要反序列化包含JSON格式数据但没有根元素的字符串

数据(简化!(是这个

[{"ID":"974",
"DataIns":"2022-08-12 14:13:26",
"NumeroFattura":"CTD18473",
"DataFattura":"2022-08-08",
"RagSocMit":"Example1"},
{"ID":"973",
"DataIns":"2022-08-12 13:31:00",
"NumeroFattura":"CTCC10189",
"DataFattura":"2022-08-08",
"RagSocMit":"Example2"},
{"ID":"971",
"DataIns":"2022-08-09 15:30:29",
"NumeroFattura":"C18474",
"DataFattura":"2022-08-08",
"RagSocMit":"Example2"}]

和用于反序列化的类是这个

Public Class TestClass
Public Property ID As String
Public Property DataIns As String
Public Property NumeroFattura As String
Public Property DataFattura As String
Public Property RagSocMit As String
End Class

如果我尝试使用此代码进行反序列化

Dim result As String = ""
Dim ListaFatture As FattureAC2
...
result = reader.ReadToEnd'contain the sting json from a WS
ListaFatture = JsonConvert.DeserializeObject(Of IEnumerable(Of FattureAC2))(result)

ListaFature等于NOTHING

有人能帮我吗?

Tnx

Salvo

您不能反序列化为IEnumerable,您必须选择需要什么数组或列表,例如

Dim ListaFatture As List (Of TestClass)
ListaFatture = JsonConvert.DeserializeObject(Of List(Of TestClass))(result)

相关内容

  • 没有找到相关文章

最新更新