将 JSON 传递给需要 List的 PageMethod范围
我有一个具有以下签名的 ASP.NET PageMethod:
<WebMethod()> _
Public Shared Function SaveCodes(ByVal codes As List(Of Code)) As String
我试图从客户端将 JSON 对象传递给 PageMethod,但出现错误,指出 String 类型无法转换为 List类型;
。
这是我在客户端构建并发送到方法的 json:
{
“代码”:{
{ "companyID": "00000000-0000-0000-0000-000000000000", "customerType":"1", "code":"11 " },
{ "companyID": "00000000-0000-0000-0000-000000000000", "customerType":"1", "code":"21 " }
}
这
是我的 PageMethod 调用,(objects 是上面的 json 字符串):
PageMethods.SaveCodes(objects, successFn, errorFn);
我已经能够传递简单的数据类型和 Code 类的单个实例,但我似乎找不到将 List 传递给的神奇之处服务器方法。谁能告诉我我做错了什么?
I have an ASP.NET PageMethod with the following signature:
<WebMethod()> _
Public Shared Function SaveCodes(ByVal codes As List(Of Code)) As String
I am trying to pass a JSON object to the PageMethod from the client side, but I get an error that the type String cannot be converted to type of List<Code>
.
Here is the json that I'm building on the client and sending to the method:
{
'codes' : {
{ "companyID": "00000000-0000-0000-0000-000000000000", "customerType":"1", "code":"11 " },
{ "companyID": "00000000-0000-0000-0000-000000000000", "customerType":"1", "code":"21 " }
}
}
Here is my PageMethod call, (objects is the json string above):
PageMethods.SaveCodes(objects, successFn, errorFn);
I have been able to pass in simple data types and a single instance of the Code class, but I can't seem to find the magic to pass a List to the server method. Can anyone show me what I'm doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我能够弄清楚。下面列出了正确的表示法。缺少的主要部分是每个对象的 __type 属性。我必须在从 PageMethod 返回的列表中进行挖掘才能找到它。
I was able to figure it out. The correct notation is listed below. The main piece that was missing was the __type property for each object. I had to dig around in a List that was returned from a PageMethod to find that.