ASP.NET [WebMethod], does it always return XML开发者_如何学C?
I know it can only return serializable data types however can it for instance return a JSON?
As I'm aware of, you can return XML or JSON.
To return JSON add this annotation or your method:
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
And on your class allow ScriptService
[ScriptService]
An example:
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public Dictionary<string, object> Test()
{
var ret = new Dictionary<string, object>();
ret.Add("Test", 1);
return ret;
}
// result:
{d:{Test:1}}
精彩评论