问题描述
我正在使用在Visual Basic .NET 3.5中编程的Web服务来接收从其他应用程序发送的JSON数组.
I'm using a web service programmed in Visual Basic .NET 3.5 to receive a JSON Array sent from other application.
我正在发送一个像这样的JSON字符串:
I'm sending a JSON string like this one:
[{"idRecoleccion":1,"PIN":"553648138"},{"idRecoleccion":2,"PIN":"553648138"}]
我正在Visual Basic .NET中收到如下代码:
And I'm receiving the code in Visual Basic .NET as follows:
<WebMethod()> _
Public Function ConfirmaRecol(ByVal ArrayConfirma() As cConfirmaRecoleccion) As Boolean
For X = 0 To ArrayConfirma.Length -1
' Usage example
ArrayConfirma(X).PIN
ArrayConfirma(X).idRecoleccion
End If
Next
End Function
我正在以这种方式定义类cConfirmaRecolecciones:
And I'm defining the class cConfirmaRecolecciones this way:
Public Class cConfirmaRecoleccion
Dim p_idRecoleccion As Integer
Dim p_PIN As String
Public Property idRecoleccion() As Integer
Get
Return p_idRecoleccion
End Get
Set(ByVal value As Integer)
p_idRecoleccion = value
End Set
End Property
Public Property PIN() As String
Get
Return p_PIN
End Get
Set(ByVal value As String)
p_PIN = value
End Set
End Property
End Class
我只想能够使用JSON发送的1整数和1字符串的数组,这就是我尝试以他的方式使用它的原因.
I just want to be able to use the array of 1 integer and 1 string that was sent by JSON that's why I'm trying to use it his way.
几件重要的事情要知道:
Few important things to know:
- 我已经能够将Web服务与参数更简单的方法一起使用,因此我必须使用Web服务的配置是正确的.
这是我在服务器上收到的错误:
This is the error I'm getting by the server:
{"Message":"Type \u0027System.Collections.Generic.IDictionary`2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Object, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]\u0027 is not supported for deserialization of an array.","StackTrace":" at System.Web.Script.Serialization.ObjectConverter.ConvertListToObject(IList list, Type type, JavaScriptSerializer serializer, Boolean throwOnError, IList& convertedList)\r\n at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeInternal(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject)\r\n at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeMain(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object& convertedObject)\r\n at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToType(Object o, Type type, JavaScriptSerializer serializer)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit)\r\n at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize[T](String input)\r\n at System.Web.Script.Services.RestHandler.GetRawParamsFromPostRequest(HttpContext context, JavaScriptSerializer serializer)\r\n at System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData methodData, HttpContext context)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.InvalidOperationException"}
您对我如何在Visual Basic .NET中接收自定义对象数组有其他建议吗?
Do you gurus have any other suggestion on how I can receive an Array of custom objects in Visual Basic .NET?
推荐答案
我找到了解决方案,这是正确的方法:
I found the solution, this was the right way:
{"ArrayConfirma": [{"idRecoleccion":1,"PIN":"553648138"},{"idRecoleccion":2,"PIN":"553648138"}]}
我必须使用Web服务方法正在接收的参数名称指定一个数组.
I had to specify an array with the name of the argument that the web service method is receiving.
这篇关于在Web服务中接收JSON数组作为参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!