示例#1
0
        public void listCategory(HttpContext context)
        {
            context.Response.ContentType     = "text/plain";
            context.Request.ContentEncoding  = Encoding.UTF8;
            context.Response.ContentEncoding = Encoding.UTF8;
            List <Category>             list       = requirementService.getAllCategory();
            StringBuilder               jsonString = new StringBuilder();
            Dictionary <String, Object> dictionary = new Dictionary <string, object>();

            jsonString.Append("[");
            int i = 1;

            foreach (Category category in list)
            {
                dictionary.Add("categoryId", category.Id);
                dictionary.Add("categoryName", category.CategoryName);
                jsonString.Append(JsonUtil.toJson(dictionary));
                if (i < list.Count)
                {
                    jsonString.Append(",");
                }
                i++;
                dictionary.Clear();
            }
            jsonString.Append("]");
            context.Response.Write(jsonString.ToString());
        }