我有一个包含销售数据的 Sale 类,然后我在 Sale 类中有一个属性,它是 SaleItem 类的列表。
Sale
-date
-SaleItems <-- List(Of SaleItem)
-total
SaleItem 类
SaleItem
-productID
-amt
-qty
当我转换为 Json 字符串并调试打印输出时。SaleItems 没有编码,只是丢失了。
我做错了什么,或者这可能是一个错误?
编辑
销售类
Public Class Sale
Private _Paid As Decimal
Private _ListSaleItems As List(Of SaleItem)
Public Sub New()
ClearSaleItem()
End Sub
Public ReadOnly Property SaleItems() As List(Of SaleItem)
Get
Return _ListSaleItems
End Get
End Property
Public Property Paid() As Decimal
Get
Return _Paid
End Get
Set
_Paid = value
End Set
End Property
Public Sub ClearSaleItem()
_ListSaleItems = New List(Of SaleItem)()
End Sub
Public Function AddSaleItem(value As SaleItem) As Decimal
If value Is Nothing Then
Throw New ApplicationException("SaleItem cannot be empty")
End If
_ListSaleItems.Add(value)
End Function
End Class
Saleitem类
Public Class SaleItem
Private _ID As Int32
Private _Quantity As Int32
Private _SellPrice As Decimal
Public Sub New()
_Quantity = 0
_SellPrice = 0
End Sub
Public Property SellPrice() As Decimal
Get
Return _SellPrice
End Get
Set
_SellPrice = value
End Set
End Property
Public Property Quantity() As Int32
Get
Return _Quantity
End Get
Set
_Quantity = value
End Set
End Property
End Class
我用来转换的代码是
sockClient.Send(fastJSON.JSON.ToJSON(ObjSales))