我遇到了同样的问题,并包含以下代码以使其正常工作。
[WebMethod][scriptMethod(UseHttpGet=true ,ResponseFormat = ResponseFormat.Json)]public void HelloWorld(){ Context.Response.Clear(); Context.Response.ContentType = "application/json"; Context.Response.Write("Hello World"); //return "Hello World";}更新:
要获得纯json格式,您可以使用如下的javascript序列化程序。
public class WebService1 : System.Web.Services.WebService{ [WebMethod] [scriptMethod(UseHttpGet=true ,ResponseFormat = ResponseFormat.Json)] public void HelloWorld() { JavascriptSerializer js = new JavascriptSerializer(); Context.Response.Clear(); Context.Response.ContentType = "application/json"; HelloWorldData data = new HelloWorldData(); data.Message = "HelloWorld"; Context.Response.Write(js.Serialize(data)); }}public class HelloWorldData{ public String Message;}但是,这适用于复杂类型,但字符串没有任何区别。



