C# JavaScriptSerializer 序列化集合

        //测试对象集合序列化
        public void jsonTest()
        {
            List<moduleEntity> list = new List<moduleEntity>();
            for (int i = 1; i < 5;i++)
            {
                moduleEntity entity = new moduleEntity();
                entity.id = i + "0";
                entity.sortNumber = i;
                entity.moduleFlag = "flag"+i;
                entity.moduleName = "name"+i;
                entity.moduleUrl = "url" + i;
                entity.moduleImage = "image" + i;
                entity.createDatetime = DateTime.Now;
                list.Add(entity);

            }
            JavaScriptSerializer jss = new JavaScriptSerializer();
            string jsonString = jss.Serialize(list);
            this.Response.Write(list);
        }

 

posted @ 2014-08-01 16:25  大空白纸  阅读(656)  评论(0编辑  收藏  举报