首页 > 解决方案 > 如何将属性定义为可选

问题描述

我有以下课程

    Private Class OCOOrderRecord
        Public Property orderListId As Integer
        Public Property contingencyType As String
        Public Property listStatusType As String
        Public Property listOrderStatus As String
        Public Property listClientOrderId As String
        Public Property transactionTime As Long
        Public Property symbol As String
        Public Property orders As List(Of OrdersRecord)
        Public Property orderReports As List(Of OrderReportsRecord)
    End Class

    Private Class OrdersRecord
        Public Property symbol As String
        Public Property orderId As Integer
        Public Property clientOrderId As String
    End Class

    Private Class OrderReportsRecord
        Public Property symbol As String
        Public Property orderId As Integer
        Public Property orderListId As Integer
        Public Property clientOrderId As String
        Public Property transactTime As Long
        Public Property price As String
        Public Property origQty As String
        Public Property executedQty As String
        Public Property cummulativeQuoteQty As String
        Public Property status As String
        Public Property timeInForce As String
        Public Property type As String
        Public Property side As String
        Public Property stopPrice As String
    End Class

我收到的 JSON 响应在 orderReports 属性中有两个项目。第一个包含 stopPrice 值,但第二个没有。所以我无法正确解析它。任何帮助将不胜感激。

标签: jsonclassproperties

解决方案


我通过编辑响应并为 stopPrice 属性添加一个空值来做到这一点


推荐阅读