首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

请问MVC序列化和反序列化

2013-01-28 
请教MVC序列化和反序列化我有一个对象public class Bulletin{public Bulletin(){this.BulletinImgs new

请教MVC序列化和反序列化
我有一个对象
public class Bulletin
    {
        public Bulletin()
        {
            this.BulletinImgs = new List<BulletinImg>();
            this.ScreenClients = new List<ScreenClient>();
        }

        public int BulletinID { get; set; }
        public string Title { get; set; }
        public string Message { get; set; }
        public string Category { get; set; }
        public Nullable<System.DateTime> LastDate { get; set; }
        public string LastUserCD { get; set; }
        public virtual ICollection<BulletinImg> BulletinImgs { get; set; }
        public virtual MasterData MasterData { get; set; }
        public virtual ICollection<ScreenClient> ScreenClients { get; set; }
    }

调用Json(bulletin, JsonRequestBehavior.AllowGet)进行序列化,没有任何问题。但在$.getJSON中的回调函数没有反应,比如:$.getJSON("/Home/GetBulletinDetail/", { id: 1 }, function (data) { alert(data); });浏览器不会弹出对话框。
但把Bulletin对象中的后三个virtual属性去掉,就一起正常,请问有其他好办法解决吗??
[解决办法]
string result = "";
            JavaScriptSerializer jss = new JavaScriptSerializer();
            result = jss.Serialize(list);
            Response.Write(result);
list是要序列化的对象
[解决办法]
ICollection<ScreenClient> 改成 ?List<ScreenClient> 试试

热点排行