我在控制器中有以下代码。
class Person
{
public string Name { get; set; }
public int Age { get; set; }
public DateTime Birthday { get; set; }
}
public ActionResult JsonObject()
{
Person[] persons = new Person[]{
new Person{Name="John", Age=26, Birthday=new DateTime(1986,1,1)},
new Person{Name="Tom", Age=10, Birthday=new DateTime(2002, 1, 9)}
};
return Json(persons, JsonRequestBehavior.AllowGet);
}
通常,我得到这样的结果: [{"Name":"John","Age":26,"Birthday":"/Date(504892800000)/"},{"Name":"Tom","Age ":10,"生日":"/日期(1010505600000)/"}]
没关系,但是,我想为用户做一个选项:不显示生日。因此,预期结果将是这样的: [{"Name":"John","Age":26},{"Name":"Tom","Age":10}]
如何不将生日属性序列化为 JSON?