I'm using a web service programmed in Visual Basic .NET 3.5 to receive a JSON Array sent from other application.
I'm sending a JSON string like this one:
[{"idRecoleccion":1,"PIN":"553648138"},{"idRecoleccion":2,"PIN":"553648138"}]
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
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
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:
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"}
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"}]}
I had to specify an array with the name of the argument that the web service method is receiving.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With