vb.net 格式化 Web 服务的数据结构输入
vb.net Formatting data structure input for web service
(修改后的问题)
我需要为 RPG Web 服务格式化输入数据结构。我试过使用列表但它不起作用。当我尝试此代码时:
Dim clist As New List(Of LabelView.PASSBACK.dscustomers)
clist.Add(New LabelView.PASSBACK.dscustomers() With {.BALANCEDUE = 185.42, .CREATIONDATE = 20200101, .CUSTOMERID = 1, .CUSTOMERTYPE = "ACTIVE", .FIRSTNAME = "Pat", .LASTNAME = "Smith"})
clist.Add(New LabelView.PASSBACK.dscustomers() With {.BALANCEDUE = 185.42, .CREATIONDATE = 20200101, .CUSTOMERID = 2, .CUSTOMERTYPE = "ACTIVE", .FIRSTNAME = "Jordan", .LASTNAME = "Jones"})
input.DSCUSTOMERS = clist
// ^^ Intellisense error:
// Value of type 'List (Of dsCustomers)' cannot be converted to 'dscustomers()'.
我不知道如何以编程方式构建兼容的东西。当我尝试这个时:
Dim client As PASSBACK.PASSBACK = New PASSBACK.PASSBACK()
Dim input As PASSBACK.passbackInput = New PASSBACK.passbackInput
input.DSCUSTOMERS(0).FIRSTNAME = "Hello"
它编译但是当我 运行 我得到 'Object reference not set to an instance of an object.'
你对这行的问题:
input.DSCUSTOMERS = clist
是因为DCUSTOMERS
是一个数组(你报错的"dcustomers()"),一个List(Of dcustomer)
不能直接赋值给数组
List(Of T)
上有一个转换函数,可以为您提供一个名为 ToArray
的数组 T()
。它只需要对您的代码进行少量更改:
input.DSCUSTOMERS = clist.ToArray()
这将创建一个与 List
具有相同内容的新数组(如果 dcustomers
是一个 Class
那么数组的内容将是完全相同的对象,而如果它是 Structure
那么它们将是副本)并将其分配给 DCUSTOMERS
.
(修改后的问题)
我需要为 RPG Web 服务格式化输入数据结构。我试过使用列表但它不起作用。当我尝试此代码时:
Dim clist As New List(Of LabelView.PASSBACK.dscustomers)
clist.Add(New LabelView.PASSBACK.dscustomers() With {.BALANCEDUE = 185.42, .CREATIONDATE = 20200101, .CUSTOMERID = 1, .CUSTOMERTYPE = "ACTIVE", .FIRSTNAME = "Pat", .LASTNAME = "Smith"})
clist.Add(New LabelView.PASSBACK.dscustomers() With {.BALANCEDUE = 185.42, .CREATIONDATE = 20200101, .CUSTOMERID = 2, .CUSTOMERTYPE = "ACTIVE", .FIRSTNAME = "Jordan", .LASTNAME = "Jones"})
input.DSCUSTOMERS = clist
// ^^ Intellisense error:
// Value of type 'List (Of dsCustomers)' cannot be converted to 'dscustomers()'.
我不知道如何以编程方式构建兼容的东西。当我尝试这个时:
Dim client As PASSBACK.PASSBACK = New PASSBACK.PASSBACK()
Dim input As PASSBACK.passbackInput = New PASSBACK.passbackInput
input.DSCUSTOMERS(0).FIRSTNAME = "Hello"
它编译但是当我 运行 我得到 'Object reference not set to an instance of an object.'
你对这行的问题:
input.DSCUSTOMERS = clist
是因为DCUSTOMERS
是一个数组(你报错的"dcustomers()"),一个List(Of dcustomer)
不能直接赋值给数组
List(Of T)
上有一个转换函数,可以为您提供一个名为 ToArray
的数组 T()
。它只需要对您的代码进行少量更改:
input.DSCUSTOMERS = clist.ToArray()
这将创建一个与 List
具有相同内容的新数组(如果 dcustomers
是一个 Class
那么数组的内容将是完全相同的对象,而如果它是 Structure
那么它们将是副本)并将其分配给 DCUSTOMERS
.