以下JSON字符串由我们使用的软件的api提供。我无法控制JSON的格式,因此这是我必须使用的方法。我在正确设置类结构时遇到以下JSON字符串问题。以下是我尝试的一些代码示例。任何帮助将非常感激。
我遇到问题的特定区域是group_access对象。我相信这些是整数数组。我试图将其转换为列表,
Public Property group_access As List(Of List(Of Array))
。
我还尝试为对象提供自己的类
Public Property group_access As GroupAccess
Public Class GroupAccess
Public Property Result As Dictionary(Of Integer, List(Of List(Of Integer)))
End Class
JSON数据:
{""type"":""users"",""limit"":1,""offset"":0,""total"":440,""time"":""0.029s"",""items"":[{""id"":170336,""email"":""tina.doe@email.org"",""fname"":""Tina"",""full_name"":""Tina Doe"",""grades"":[],""group_access"":{""27913"":2,""27898"":0,""28014"":0,""27934"":0},""last_login"":""2019-04-04
20:51:49"",""lname"":""Doe"",""resource_id"":""O97I0G5BU"",""roles"":{""27913"":{""2017"":2,""2018"":2},""27898"":{""2017"":0,""2018"":0},""28014"":{""2018"":0},""27934"":{""2017"":0,""2018"":0}},""tags"":[""AZ - Maryvale"",""Arizona""],""title"":"""",""inactive_group_ids"":[27934],""active"":true,""targets"":[""Leader
Development Target""],""caseload_tags"":[]}],""items_count"":1}
班级数据:
Public Class Item
Public Property id As Integer
Public Property email As String
Public Property fname As String
Public Property lname As String
Public Property full_name As String
Public Property resource_id As String
Public Property title As String
Public Property tags As IList(Of String)
Public Property grades As IList(Of String)
Public Property targets As IList(Of String)
Public Property group_access As Dictionary(Of Integer, List(Of List(Of Double)))
End Class
Public Class RootObject
Public Property type As String
Public Property limit As Integer
Public Property offset As Integer
Public Property total As Integer
Public Property time As String
Public Property items As List(Of Item)
Public Property items_count As Integer
End Class
答案 0 :(得分:0)
在您的json有效负载中,group_access
对象看起来像一个简单的字典。因此,相应的类型应类似于:
Dictionary(Of Integer, Integer)
最终班级:
Public Class Item
// ...
Public Property group_access As Dictionary(Of Integer, Integer)
// ...
End Class
Public Class RootObject
// ...
Public Property items As List(Of Item)
// ...
End Class