public void listByCategory(HttpContext context) { context.Response.ContentType = "text/plain"; List <Requirement> list = requirementService.getRequirementListByCategory(Convert.ToInt32(context.Request["categoryId"].ToString())); StringBuilder jsonString = new StringBuilder(); Dictionary <String, Object> dictionary = new Dictionary <string, object>(); string imgPath = "hotel1.jpg"; if (list.Count == 0) { context.Response.Write("{\"success\":\"false\"}"); return; } jsonString.Append("["); int i = 1; foreach (Requirement requirement in list) { RequirementImg requirementImg = requirementService.getRequirementFirstImg(requirement.Id); if (requirementImg.ImgPath != null) { imgPath = System.IO.Path.GetFileName(requirementImg.ImgPath); } dictionary.Add("Id", requirement.Id); dictionary.Add("Name", requirement.RequirementName); dictionary.Add("Desc", requirement.RequirementDesc); dictionary.Add("categoryId", requirement.RequirementCategory.Id); dictionary.Add("priority", requirement.Priority); dictionary.Add("userId", requirement.User.Id); dictionary.Add("nickName", requirement.User.NickName); dictionary.Add("teleNumber", requirement.User.TeleNumber); dictionary.Add("createTime", requirement.CreateTime); dictionary.Add("modifyTime", requirement.ModifyTime); dictionary.Add("Status", requirement.RequirementStatus); dictionary.Add("FirstImgPath", imgPath); dictionary.Add("success", "true"); jsonString.Append(JsonUtil.toJson(dictionary)); if (i < list.Count) { jsonString.Append(","); } i++; dictionary.Clear(); } jsonString.Append("]"); context.Response.Write(jsonString.ToString()); }