I am using a web service programmed in Visual Basic.NET 3.5 to get a JSON array sent from another application.
I am sending a JSON string similar to this:
[{"idRecoleccion":1,"PIN":"553648138"},{"idRecoleccion":2,"PIN":"553648138"}]
And I get 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 define the cConfirmaRecolecciones class as follows:
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 use an array of 1 integers and 1 string that was sent by JSON, so I'm trying to use it my own way.
A few important things to know:
- I was able to use web services with methods that have simpler arguments, so the configurations that I have to use web services are correct.
This is the error I get from 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 have a guru any other suggestion on how I can get an array of user objects in Visual Basic.NET?
Any help would be greatly appreciated!