用webservice搭建一个简易服务器时,返回字符串总数会自动增加 <?xml version="1.0" encoding="utf-8"?> 这些额外东西。
[WebMethod]
public void K3Infos()
{
string ss = "{"name":"ABC"}";
this.Context.Response.Clear();
this.Context.Response.ContentType = "application/json;charset=utf-8";
this.Context.Response.Write(ss);
this.Context.Response.Flush();
this.Context.Response.End();
}
返回值不是string,改成void,然后通过response写入需要的json字符串.