web的代码改如何实现
public String AdminLogin(String openid)
{
String a ="2";
try
{
string sql = "select * from [UserData] where openid='" +openid + "'";
SqlCommand cmd = new SqlCommand(sql, sqlCon);
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
a = "1";
}
reader.Close();
cmd.Dispose();
}
catch (Exception)
{
throw;
}
return a;
}
namespace NatLIMS
{
/// <summary>
/// WebService2 的摘要说明
/// </summary>
[WebService(Namespace = "localhost")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。
// [System.Web.Script.Services.ScriptService]
public class WebService2 : System.Web.Services.WebService
{
DBOperation dbOperation = new DBOperation();
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
public string AdminLogin(String openid)
{
return dbOperation.AdminLogin(openid);
}
}
}
如何返回的查询结果是json格式而不是xml格式的