private HttpResponse Response;
private HttpRequest Request;
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
Response = HttpContext.Current.Response;
Request = HttpContext.Current.Request;
string mothed= Request["mothed"];
if (mothed == "1")
{
string str = "{'records':[{'Name':'Alfreds Futterkiste','City':'Berlin','Country':'Germany'},{'Name':'Ana Trujillo Emparedados y helados','City':'México D.F.','Country':'Mexico'}]}";
JavaScriptSerializer jss = new JavaScriptSerializer();
Response.Write(jss.Serialize(str));
}
//switch (mothed)
//{
// case "1":
// Console.WriteLine("haha");
// break;
// default:
// Console.WriteLine("NO");
// break;
//}
//if (!string.IsNullOrEmpty(mothed))
//{
// System.Reflection.MethodInfo Method = this.GetType().GetMethod(mothed, System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);//通过反射机制,直接对应到相应的方法
// if (Method != null)
// {
// Method.Invoke(this, new object[] { context });
// }
//}
//else
//{
// context.Response.Redirect("~/Login.aspx");
//}
}
/// <summary>
/// 将数据表序列化为json格式数据返回
/// </summary>
/// <param name="table"></param>
/// <returns></returns>
private string DataTableJSON(DataTable table)
{
List<Dictionary<string, object>> list = new List<Dictionary<string, object>>();
foreach (DataRow row in table.Rows)
{
Dictionary<string, object> dict = new Dictionary<string, object>();
foreach (DataColumn col in table.Columns)
{
dict[col.ColumnName] = row[col];
}
list.Add(dict);
}
JavaScriptSerializer jss = new JavaScriptSerializer();
return jss.Serialize(list);
}
public bool IsReusable
{
get
{
return false;
}
}
}
}