为什么JavaScriptSerializer.Serialize()永远不会返回

时间:2015-03-23 17:50:22

标签: c# asp.net json entity-framework-6

我试图将C#对象序列化为JSON对象。这是代码:

QuestionGroup group = DatabaseMethods.GetQuestionGroup(questionGroupID);
JavaScriptSerializer jSer = new JavaScriptSerializer();
string json = jSer.Serialize(group);

group在第1行之后看起来如预期。第三行永远不会返回任何内容,我无法进入该函数;我只能查看元数据,但它没有提及任何相关内容。我没有得到例外;它只是......永远......回归。

我传递的对象是一个非常野兽的阶级,有孩子和孙子。它是EF课程;我不知道这是否会以某种方式搞乱JSON序列化程序。它应该采取任何对象,所以我不知道那会怎样;但是谁知道呢。

这是一个类,删除了一些代码以简洁:

public class QuestionGroup
{
    public Int32 QuestionGroupID { get; set; }
    public Int32 Order { get; set; }

    [Display(Name = "Path to File", Prompt = "Path to File")]
    [DataType(DataType.Upload)]

    [NotMapped]
    public HttpPostedFileWrapper PathToFile { get; set; }
    public String FileName { get; set; }
    public virtual Image Image { get; set; }
    public Int32? ImageID {get; set; }

    public String Text { get; set; }
    public DateTime WhenCreated { get; set; }
    public Int32 CreatedBy { get; set; }

    [NotMapped]
    public Int32 MasteryCriteriaNumerator { get; set; }
    [NotMapped]
    public Int32 MasteryCriteriaDenominator { get; set; }

    public Boolean TeacherAdministersToStudent { get; set; }

    /*Foreign keys for associations*************************************************/
    public Guid MasteryObjectiveID { get; set; }

    /*Navigational properties for EF************************************************/
    public MasteryObjective MasteryObjective {
        get { return DAL.DatabaseMethods.GetMasteryObjective(MasteryObjectiveID); }
    }
    public List<Question> Questions{ get; set; }
    public virtual List<Assessment> Assessments { get; set; }
    public virtual List<MultipleChoiceResult> MultipleChoiceResults { get; set; }

    // The full url to qg's image on rackspace
    [NotMapped]
    public String RackspaceFullURL { get { return GetRackspaceURL(QuestionGroupID, FileName); } }

    private String GetRackspaceURL(Int32 QuestionGroup, String FileName)
    {
        //code removed
    }
}

0 个答案:

没有答案