public void listByCategory(HttpContext context) { context.Response.ContentType = "text/plain"; List <Supply> list = supplyService.getSupplyListByCategory(Convert.ToInt32(context.Request["categoryId"].ToString())); StringBuilder jsonString = new StringBuilder(); Dictionary <String, Object> dictionary = new Dictionary <string, object>(); //jsonString.Append("\"supply\":"); string imgPath = "defaultImg.jpg"; if (list.Count == 0) { context.Response.Write("{\"success\":\"false\"}"); return; } jsonString.Append("["); int i = 1; foreach (Supply supply in list) { SupplyImg supplyImg = supplyService.getSupplyFirstImg(supply.Id); if (supplyImg.ImgPath != null) { imgPath = System.IO.Path.GetFileName(supplyImg.ImgPath); } dictionary.Add("Id", supply.Id); dictionary.Add("Name", supply.SupplyName); dictionary.Add("Desc", supply.SupplyDesc); dictionary.Add("categoryId", supply.SupplyCategory.Id); dictionary.Add("priority", supply.Priority); dictionary.Add("userId", supply.User.Id); dictionary.Add("nickName", supply.User.NickName); dictionary.Add("teleNumber", supply.User.TeleNumber); dictionary.Add("createTime", supply.CreateTime); dictionary.Add("modifyTime", supply.ModifyTime); dictionary.Add("Status", supply.SupplyStatus); 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()); }