下面的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"":""[email protected]"",""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
在你的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