Webservice returns XML by default. To return json, convert the object to a json string using the json tool class and then output
Copy codeThe Code is as follows:
[WebService (Namespace = "http://tempuri.org/")]
[WebServiceBinding (ConformsTo = WsiProfiles. BasicProfile1_1)]
// To allow ASP. net ajax to call this Web service from a script, uncomment the following line.
// [System. Web. Script. Services. ScriptService]
Public class WebService2: System. Web. Services. WebService
{
Public WebService2 ()
{
// If you use the designed component, uncomment the following line
// InitializeComponent ();
}
[WebMethod]
Public void HelloWorld ()
{
User user = new User ();
User. UserName = "aa ";
User. UserPhone = "bb ";
// Mainly the following two sentences
Context. Response. Write (JsonHelper. ObjectToJson (user ));
Context. Response. End ();
// No return value is required
// Return JsonHelper. ObjectToJson (user );
}
}