在客户端
var pre = "{\"objEmployees\": {\"Employee\": [{";
var array = JSON.stringify(employee);
var last = "}}";
var ArrayofObjects = pre + array + last;
DoSort(ArrayofObjects);
function DoSort(ArrayofObjects) {
$.ajax({
type: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8",
url: "http://localhost:50214/CMSWebService.asmx/sorting",
data: ArrayofObjects,
success: function (response) {
alert('done');
},
error: function (response) {
alert(response.d);
}
});
}
这是我的实体
[Serializable]
public class Employee
{
public string id;
public string order;
}
public class Employees :List<Employee>
{
}
在Web服务的服务器端
[WebMethod]
[WebInvoke(RequestFormat=WebMessageFormat.Json)]
[ScriptMethod(ResponseFormat= ResponseFormat.Json)]
public string sorting(Employees objEmployees)
{
int ID = Convert.ToInt32(objEmployees[0].id);
int Order = Convert.ToInt32(objEmployees[0].order);
// Update code....
return "true";
}
此代码命中我的服务,但我无法在webservice中提取值。我得到null对象。即使webservice的签名与ajax调用中的数据匹配。
答案 0 :(得分:0)
我得到了答案
var array = JSON.stringify(objemployee: employee);