0

I am getting an error when I Deserialize o. o is made up of many cars and I am trying to deseralize them to oCarsList. I tried to change o to ByVal o As List(Of Cars)(), but I got a javascript error.

Javascript

var str2 = JSON.stringify({CarsObject: Cars});

    $.ajax({
        type: "POST",
        url: "wsCars.asmx/SetCars",
        //data: Cars,
        //data: {"Cars":Cars.toString()},
        data: "{o: " + str2 + "}",
        processData: false,
        //contentType: "plain/text",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function(msg) {
            alert(msg.d);

        },
        error: function(e) {
            alert(e);
        }
    });

VB

    Public Function SetCars(ByVal o As Object) As String 
        If o.Count > 0 Then

            Dim oSerializer As New JavaScriptSerializer
            Dim oCarsList As New List(Of Cars)()

            Try
                oCarsList = oSerializer.DeserializeObject(o)
            Catch ex As Exception
            End Try
        End If
    End Function
Etch
  • 3,044
  • 25
  • 31
user1167466
  • 333
  • 1
  • 4
  • 14

1 Answers1

0

I would suggest doing this instead of running stringify then concatenating a JSON element as a string.

var str2 = JSON.stringify({o:{CarsObject: Cars}});
Etch
  • 3,044
  • 25
  • 31