日期:2014-05-17  浏览次数:20448 次

请教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> 试试