0
當反序列化o時出現錯誤。 O由許多汽車組成,我試圖將它們非傳遞給oCarsList。我試圖將o更改爲ByVal o作爲列表(汽車)(),但我得到了一個javascript錯誤。將Json傳遞給WebMethod
的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