【发布时间】:2009-06-30 05:33:48
【问题描述】:
我在过去 3 个小时里一直在研究这段代码并试图找到答案。由于我没有成功,我将发布代码并询问我应该在我的 Web 服务上使用哪种参数来处理此请求:
var args = [{ key: 'myId', value: 'myValue' }, { key: 'myOtherId', value: 'myOtherValue'}];
var dataToSend = { name: 'fooId', value: 'fooValue', args: args };
$.ajax({
type: 'POST',
url: 'fooURL',
data: dataToSend,
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: OnSuccess,
error: OnError
});
现在,我应该需要哪种签名才能获得我的“dataToSend”?
我试过了:
[WebMethod, ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string Foo(string name, object value, List<Args> args)
{
return "OK";
}
public class Args
{
public string key { get; set; }
public object value { get; set; }
}
和
[WebMethod, ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string Foo(string name, object value, object[] args)
{
return "OK";
}
还有
[WebMethod, ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string Foo(dataToSend dataToSend)
{
return "OK";
}
public class dataToSend
{
public string name { get; set; }
public object value { get; set; }
public List<Args> args = new List<Args>();
}
public class Args
{
public string key { get; set; }
public object value { get; set; }
}
【问题讨论】: