0

我是这个话题的新手,基本上我有这个 JSON 字符串:

"{"payChannleResult":{"lastestPayChannel":"","supportedPayChannelList":{"supportTopPayChannel":[{"name":"FastPay","cashierCode":"CREDITCARD","supportSecPayChannelList":{"supportSecPayChannel":[{"name":"BankA","cashierCode":"CREDITCARD_A"},{"name":"BankB","cashierCode":"CREDITCARD_B"},
{"name":"BankE","cashierCode":"CREDITCARD_E"},
{"name":"More","cashierCode":"CREDITCARD"}]}},
{"name":"Credits","cashierCode":"DEBITCARD","supportSecPayChannelList":{"supportSecPayChannel":[{"name":"BankF","cashierCode":"DEBITCARD_F"},
{"name":"BankI","cashierCode":"DEBITCARD_I"},
{"name":"More","cashierCode":"DEBITCARD"}]}}]}}}"

我为此开设了课程:

<Serializable()> Public Class RootObject
    Private _payChannelResult As PayChannleResult
    Public Property payChannleResult() As PayChannleResult
        Get
            Return _payChannelResult
        End Get
        Set(ByVal value As PayChannleResult)
            _payChannelResult = value
        End Set
    End Property
End Class

<Serializable()> Public Class PayChannleResult
    Private _lastestPayChannel As String 'LastestPayChannel
    Private _supportedPayChannelList As SupportedPayChannelList

    Public Property lastestPayChannel() As String
        Get
            Return _lastestPayChannel
        End Get
        Set(ByVal value As String)
            _lastestPayChannel = value
        End Set
    End Property

    Public Property supportedPayChannelList() As SupportedPayChannelList
        Get
            Return _supportedPayChannelList
        End Get
        Set(ByVal value As SupportedPayChannelList)
            _supportedPayChannelList = value
        End Set
    End Property
End Class

<Serializable()> Public Class SupportedPayChannelList
    Private _supportTopPayChannel As SupportTopPayChannel
    Public Property supportTopPayChannel() As SupportTopPayChannel
        Get
            Return _supportTopPayChannel
        End Get
        Set(ByVal value As SupportTopPayChannel)
            _supportTopPayChannel = value
        End Set
    End Property
End Class


<Serializable()> Public Class SupportTopPayChannel
    Private _name As String
    Private _cashierCode As String
    Private _supportSecPayChannelList As SupportSecPayChannelList

    Public Property name() As String
        Get
            Return _name
        End Get
        Set(ByVal value As String)
            _name = value
        End Set
    End Property
    Public Property cashierCode() As String
        Get
            Return _cashierCode
        End Get
        Set(ByVal value As String)
            _cashierCode = value
        End Set
    End Property

    Public Property supportSecPayChannelList() As SupportSecPayChannelList
        Get
            Return _supportSecPayChannelList
        End Get
        Set(ByVal value As SupportSecPayChannelList)
            _supportSecPayChannelList = value
        End Set
    End Property
End Class

<Serializable()> Public Class SupportSecPayChannelList

    Private _supportSecPayChannel As List(Of SupportSecPayChannel)
    Public Property supportSecPayChannel() As List(Of SupportSecPayChannel)
        Get
            Return _supportSecPayChannel
        End Get
        Set(ByVal value As List(Of SupportSecPayChannel))
            _supportSecPayChannel = value
        End Set
    End Property
End Class

<Serializable()> Public Class SupportSecPayChannel
    Private _name As String
    Private _cashierCode As String

    Public Property name() As String
        Get
            Return _name
        End Get
        Set(ByVal value As String)
            _name = value
        End Set
    End Property
    Public Property cashierCode() As String
        Get
            Return _cashierCode
        End Get
        Set(ByVal value As String)
            _cashierCode = value
        End Set
    End Property
End Class



<Serializable()> Public Class LastestPayChannel
    Private _name As String
    Private _cashierCode As String
    Public Property name() As String
        Get
            Return _name
        End Get
        Set(ByVal value As String)
            _name = value
        End Set
    End Property
    Public Property cashierCode() As String
        Get
            Return _cashierCode
        End Get
        Set(ByVal value As String)
            _cashierCode = value
        End Set
    End Property
End Class

最后这就是我调用解串器函数的方式:

Dim seriliazer As JavaScriptSerializer = New JavaScriptSerializer
Dim p As RootObject = seriliazer.Deserialize(Of RootObject)(strJson)

但它给出了错误:不支持类型“SupportTopPayChannel”用于数组的反序列化。

请帮帮我,非常感谢!!!!!!!

4

1 回答 1

0

看起来您的 VB 类定义不太正确。SupportedPayChannelList 类具有未声明为列表的属性。使用下面的类定义(添加 List(Of 添加))。如果您还没有,请确保拥有 Imports System.Collections.Generic。

公共类 SupportedPayChannelList
    Private _supportTopPayChannel 作为列表(SupportTopPayChannel 的)
    公共属性 supportTopPayChannel() As List(Of SupportTopPayChannel)
        得到
            返回 _supportTopPayChannel
        结束获取
        Set(ByVal value As List(Of SupportTopPayChannel))
            _supportTopPayChannel = 价值
        结束集
    结束属性
结束类
于 2012-08-10T20:07:38.457 回答