DataContract Json序列化程序和项集合中缺少括号

DataContract Json序列化程序和项集合中缺少括号,json,vb.net,serialization,datacontractjsonserializer,Json,Vb.net,Serialization,Datacontractjsonserializer,当我反序列化/序列化并将数据压缩为json格式时,我的项集合缺少括号,导致它在发布到web api时失败。 以下是正确格式的json,带[]括号 { "basket": { "basket_platform_type": "in_store", "basket_currency": { "currency_id": 2, "currency_code": "ZAR" }, "b

当我反序列化/序列化并将数据压缩为json格式时,我的项集合缺少括号,导致它在发布到web api时失败。 以下是正确格式的json,带[]括号

{
    "basket": {
        "basket_platform_type": "in_store",
        "basket_currency": {
            "currency_id": 2,
            "currency_code": "ZAR"
        },
        "basket_items": [
            {
                "spaaza_product_id": 18605,
                "retailer_product_code": "WBGT0234",
                "retailer_item_code": "line_0",
                "item_quantity": 3,
                "item_price": 250
            }
        ],
        "retailer_basket_code": "70401",
        "basket_total_price": 750
    },
    "entity": {
        "entity_type": "chain",
        "entity_id": 1740,
        "branch_business_owner_code": "501",
        "branch_business_id": 1341
    },
    "user": {
        "member_programme": "spaaza",
        "member_number": "33017307"
    }
}
这就是我得到的,我错过了篮子项目的[]

{
    "basket": {
        "basket_platform_type": "in_store",
        "basket_currency": {
            "currency_id": 2,
            "currency_code": "ZAR"
        },
        "basket_items": 
            {
                "spaaza_product_id": 18605,
                "retailer_product_code": "WBGT0234",
                "retailer_item_code": "line_0",
                "item_quantity": 3,
                "item_price": 250
            },
        "retailer_basket_code": "70401",
        "basket_total_price": 750
    },
    "entity": {
        "entity_type": "chain",
        "entity_id": 1740,
        "branch_business_owner_code": "501",
        "branch_business_id": 1341
    },
    "user": {
        "member_programme": "spaaza",
        "member_number": "33017307"
    }
}
下面是我用于序列化的类和函数

Namespace Global.MyPrice

Public Class GetBasketPrice

    Public Class Entity
        Public Property entity_type As String
        Public Property entity_id As Integer
        Public Property branch_business_owner_code As String
        Public Property branch_business_id As Integer
    End Class

    Public Class User
        Public Property member_programme As String
        Public Property member_number As String
    End Class

    Public Class Basket_Currency
        Public Property currency_id As Integer
        Public Property currency_code As String
    End Class

    Public Class Rootobject
        Public Property basket As Basket
        Public Property entity As Entity
        Public Property user As User
    End Class

    Public Class Basket_Items
        Public Property spaaza_product_id As Integer
        Public Property retailer_product_code As String
        Public Property retailer_item_code As String
        Public Property item_quantity As Integer
        Public Property item_price As Single
    End Class

    Public Class Basket
        Public Property basket_platform_type As String
        Public Property basket_currency As Basket_Currency
        Public Property basket_items() As Basket_Items
        Public Property retailer_basket_code As String
        Public Property basket_total_price As Single
    End Class

End Class
结束命名空间

这是序列化函数

Dim jsonstring As String
            Dim stream1 As New MemoryStream()

            Dim ser As New DataContractJsonSerializer(GetType(MyPrice.GetBasketPrice.Rootobject))
            ser.WriteObject(stream1, MyPriceBasket)

            stream1.Position = 0

            Dim sr As New StreamReader(stream1)
            Console.Write("JSON form of Person object: ")
            jsonstring = sr.ReadToEnd()

            Console.WriteLine(jsonstring)
“basket\u items”
的值是一个JSON数组,它是一个括号内的值列表:
[value1,value2,…,valueN]
。根据DataContractJsonSerializer将“集合、字典和数组”映射到JSON数组。因此,您的
basket\u项目
属性需要是某种类型的集合,例如
列表(basket\u项目)

或者,如果您想使用数组而不是列表,则您的
()
位于错误的位置。在VB.NET中定义数组值属性:

更多。

这里的C在哪里??您正在使用VB
Public Class Basket
    Public Property basket_platform_type As String
    Public Property basket_currency As Basket_Currency
    Public Property basket_items As List(Of Basket_Items)
    Public Property retailer_basket_code As String
    Public Property basket_total_price As Single
End Class
    Public Property basket_items As Basket_Items()