<%@ WebHandler Language="C#" Class="getMobile2" %> using System; using System.Web; using System.Data; using System.Collections; public class getMobile2 : IHttpHandler { DbOperate dbo = null; public void ProcessRequest (HttpContext context) { dbo = new DbOperate(); string sql = "select * from com_yhb where IsExpired=0 and IsRSYH > 0 order by SUBSTRING(sp, 1, 1),xingming"; DataTable dt = dbo.ExecuteDataTable(sql); string sp = dt.Rows[0]["sp"].ToString().Substring(0,1); int index = 0; ArrayList list = new ArrayList(); ArrayList result = new ArrayList(); Hashtable ht = new Hashtable(); foreach (DataRow dr in dt.Rows) { if (index == 0) { ht.Add("sp",sp.ToUpper()); string[] temp = new string[2]; temp[1] = dr["xingming"].ToString(); temp[0] = dr["phone"].ToString(); list.Add(temp); index++; continue; } if (dr["sp"].ToString().Substring(0, 1) == sp) { string[] temp = new string[2]; temp[1] = dr["xingming"].ToString(); temp[0] = dr["phone"].ToString(); list.Add(temp); } else { ht.Add("children", list); result.Add(ht); sp = dr["sp"].ToString().Substring(0, 1); ht = new Hashtable(); ht.Add("sp", sp.ToUpper()); list = new ArrayList(); } } ht.Add("children", list); result.Add(ht); context.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(result)); } public bool IsReusable { get { return false; } } }