WebService default return to XML to return JSON you can use the JSON tool class to convert an object to a JSON string, and then output
Copy Code code as follows:
[WebService (Namespace = "http://tempuri.org/")]
[WebServiceBinding (ConformsTo = wsiprofiles.basicprofile1_1)]
To allow the use of ASP.net AJAX to invoke this Web service from a script, uncomment the line.
[System.Web.Script.Services.ScriptService]
public class WebService2:System.Web.Services.WebService
{
Public WebService2 ()
{
If you are using a design component, uncomment it to follow the line
InitializeComponent ();
}
[WebMethod]
public void HelloWorld ()
{
User user = new user ();
User. UserName = "AA";
User. Userphone = "BB";
It's mainly the following two sentences
Context.Response.Write (Jsonhelper.objecttojson (user));
Context.Response.End ();
No return value required
return Jsonhelper.objecttojson (user);
}
}