Deserializing JSON String to VB.net Object

后端 未结 2 1541
小蘑菇
小蘑菇 2021-01-18 14:43

I\'m trying to convert a JSON String into an VB.net Object to get easy access to alle the data in the JSON String.

My JSON String looks like this:

{
         


        
相关标签:
2条回答
  • 2021-01-18 15:11

    I converted your JSON using JsonToCSharp...and then converted the C# to vb.net...

    Public Class Datum
        Public Property clan_id() As System.Nullable(Of Integer)
            Get
                Return m_clan_id
            End Get
            Set
                m_clan_id = Value
            End Set
        End Property
        Private m_clan_id As System.Nullable(Of Integer)
        Public Property nickname() As String
            Get
                Return m_nickname
            End Get
            Set
                m_nickname = Value
            End Set
        End Property
        Private m_nickname As String
        Public Property id() As Integer
            Get
                Return m_id
            End Get
            Set
                m_id = Value
            End Set
        End Property
        Private m_id As Integer
    End Class
    
    Public Class RootObject
        Public Property status() As String
            Get
                Return m_status
            End Get
            Set
                m_status = Value
            End Set
        End Property
        Private m_status As String
        Public Property count() As Integer
            Get
                Return m_count
            End Get
            Set
                m_count = Value
            End Set
        End Property
        Private m_count As Integer
        Public Property data() As List(Of Datum)
            Get
                Return m_data
            End Get
            Set
                m_data = Value
            End Set
        End Property
        Private m_data As List(Of Datum)
    End Class
    

    Give these classes a try.

    0 讨论(0)
  • 2021-01-18 15:12

    You're close; you've got your parentheses in the wrong place. In your Rootobject class, change this line:

    Public Property data() As Datum
    

    to this:

    Public Property data As Datum()
    

    Or, this will also work:

    Public Property data As List(Of Datum)
    
    0 讨论(0)
提交回复
热议问题