【发布时间】:2014-03-11 17:08:33
【问题描述】:
我试图在 ajax 中将数组作为参数传递,但收到错误消息。请告诉我如何将数组传递给网络服务。
错误
{"Message":"Type \u0027System.String\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\u0026 convertedList)\r\n at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeInternal(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object\u0026 convertedObject)\r\n at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeMain(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object\u0026 convertedObject)\r\n at System.Web.Script.Serialization.ObjectConverter.AddItemToList(IList oldList, IList newList, Type elementType, JavaScriptSerializer serializer, Boolean throwOnError)\r\n at System.Web.Script.Serialization.ObjectConverter.ConvertListToObject(IList list, Type type, JavaScriptSerializer serializer, Boolean throwOnError, IList\u0026 convertedList)\r\n at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeInternal(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object\u0026 convertedObject)\r\n at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeMain(Object o, Type type, JavaScriptSerializer serializer, Boolean throwOnError, Object\u0026 convertedObject)\r\n at System.Web.Script.Services.WebServiceMethodData.StrongTypeParameters(IDictionary`2 rawParams)\r\n at System.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams(Object target, IDictionary`2 parameters)\r\n at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.InvalidOperationException"}
网络服务方法
[WebMethod(Description = "Add Session List")]
[ScriptMethod(UseHttpGet = false)]
public stringAddSession(string org, string ins, string brn, string startdate, string enddate, string[] classes, string[] subjects, object[] classsubjects)
{
return "abc";
}
ajax 调用
$.ajax({
type: "POST",
url: /Services/session/SessionService.asmx/AddSession,
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ 'org': OrgID, 'ins': InsID, 'brn': BrnID, 'startdate': StartDate, 'enddate': EndDate, 'classes': Classes, 'subjects': Subjects, 'classsubjects': ClassesWithSubjects };),
dataType: "json",
processData: false,
success: object,
error: function (err) {
console.log("AJAX ERROR");
alert(err.responseText);
}
});
这里是请求载荷
【问题讨论】:
标签: asp.net ajax arrays json web-services