如何发送一个哈希表到ASMX web服务? [英] How to send a hashtable to an asmx webservice?

查看:138
本文介绍了如何发送一个哈希表到ASMX web服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图发送一个哈希表来使用JSON我的web服务。但是,你不能发送一个字典类型对象(因为某些原因)。

I'm trying to send a hashtable to my webservice using JSON. However, you can't send a dictionary-type object (for some reason).

有一个解决方案,显然工程为列表(中KeyValuePair(字符串,字符串)),作为输出反正:

A solution that apparently works is "List(Of KeyValuePair(Of String, String))", as output anyway:

<WebMethod()> _
Public Function test() As List(Of KeyValuePair(Of String, String))
    Dim ret As New List(Of KeyValuePair(Of String, String))
    ret.Add(New KeyValuePair(Of String, String)("foo", "5"))
    ret.Add(New KeyValuePair(Of String, String)("bar", "baz"))
    Return ret
End Function

输出(JSON):[{关键:富,值:5},{关键:酒吧,值:巴兹}]

Outputs (in json): [{"Key":"foo","Value":"5"},{"Key":"bar","Value":"baz"}]

当我想再次提交这个在JavaScript中,我要使用此功能:

When I want to resubmit this in javascript, I have to use this function:

<WebMethod()> _
Public Sub test2(ByVal obj As List(Of KeyValuePair(Of String, String)))
    Dim dummy As UInt16 = obj.Count
End Sub

我把它用这个作为JSON参数字符串:

I call it using this as JSON parameter string:

'{"obj": [{"Key":"foo","Value":"5"},{"Key":"bar","Value":"baz"}]}'

这将返回错误。不是错误本身,而是OBJ的内容是包含2项的列表,但是当我看着他们在调试器,两者都没有(或者为null,你C#的人)。

This returns in an error. Not an error per se, but the contents of 'obj' is a list that contains 2 items, but when I look at them in the debugger, both are Nothing (or null for you C# people).

我如何发送配对数据从JavaScript来我的web服务?

How can I send paired data from javascript to my webservice?

推荐答案

如果你改变test2将收到字典对象的名单,我想你会好到哪里去。

If you change test2 to receive a List of Dictionary objects, I think you'll be good to go.

<WebMethod()> _
Public Sub test2(ByVal obj As List(Of Dictionary(Of String, String)))
    Dim dummy As UInt16 = obj.Count
End Sub

这篇关于如何发送一个哈希表到ASMX web服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆