我正在使用Visual Basic .NET 3.5中编写的Web服务来接收从其他应用程序发送的JSON数组。
我正在发送一个像这样的JSON字符串:
[{"idRecoleccion":1,"PIN":"553648138"},{"idRecoleccion":2,"PIN":"553648138"}]
我正在接收Visual Basic .NET中的代码,如下所示:
<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:
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个字符串的数组,这就是我试图以他的方式使用它的原因。
很少有重要的事情要知道:
这是我在服务器上收到的错误:
{"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中接收自定义对象数组,您是否有任何其他建议?
非常感谢任何帮助!
答案 0 :(得分:8)
我找到了解决方案,这是正确的方法:
{"ArrayConfirma": [{"idRecoleccion":1,"PIN":"553648138"},{"idRecoleccion":2,"PIN":"553648138"}]}
我必须指定一个数组,其中包含Web服务方法正在接收的参数的名称。