private void GetJsonByParentId(HttpContext context) { context.Response.ContentType = "text/plain"; Guid parentId = Guid.Empty; Guid.TryParse(context.Request.QueryString["parentId"], out parentId); if (parentId.Equals(Guid.Empty)) { context.Response.Write("{\"total\":0,\"rows\":[]}"); return; } ProvinceCity bll = new ProvinceCity(); var dic = bll.GetChild(parentId); if (dic == null || dic.Count == 0) { context.Response.Write("{\"total\":0,\"rows\":[]}"); return; } StringBuilder sb = new StringBuilder(); foreach (var item in dic) { sb.Append("{\"Id\":\"" + item.Key + "\",\"Name\":\"" + item.Value + "\"},"); } context.Response.Write("{\"total\":" + dic.Count + ",\"rows\":[" + sb.ToString().Trim(',') + "]}"); }
private void GetJsonForProvince(HttpContext context) { context.Response.ContentType = "text/plain"; ProvinceCity bll = new ProvinceCity(); var dic = bll.GetProvince(); if (dic == null || dic.Count == 0) { context.Response.Write("{\"total\":0,\"rows\":[]}"); return; } StringBuilder sb = new StringBuilder(); foreach (var item in dic) { sb.Append("{\"Id\":\"" + item.Key + "\",\"Name\":\"" + item.Value + "\"},"); } context.Response.Write("{\"total\":" + dic.Count + ",\"rows\":[" + sb.ToString().Trim(',') + "]}"); }