vb.net return json object with multiple types?

别来无恙 提交于 2019-12-02 11:15:27

I think that you would be much better off just creating a couple of classes and moving the data from the database into these classes. For example:

Public Class MyDataClass
    Public Property Page As Integer

    Public ReadOnly Property Count As Integer
        Get
            If Me.Rows IsNot Nothing Then
                Return Me.Rows.Count
            Else
                Return 0
            End If
        End Get
    End Property

    Public Property Rows As List(Of MyDataRow)

    ' Parameterless constructor to support serialization.
    Public Sub New()
        Me.Rows = New List(Of MyDataRow)
    End Sub
    Public Sub New(wPage As Integer, ds As DataSet)
        Me.New()

        Me.Page = wPage

        For Each oRow As DataRow In ds.Tables(0).Rows
            Dim oMyRow As New MyDataRow

            oMyRow.Id = oRow("id")
            oMyRow.Name = oRow("Name")

            Me.Rows.Add(oMyRow)
        Next
    End Sub
End Class

Public Class MyDataRow
    Public Property Id As Integer
    Public Property Name As String

    ' Parameterless constructor to support serialization
    Public Sub New()

    End Sub
End Class

Then change the return type of the method to MyDataClass and change the return to:

        Return New MyDataClass(1, ds)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!