我试图在 json NET 中的反序列化对象期间设置类属性将电子邮件值设置为大写,但它在构造函数中不起作用
这是我的代码:
帐户类
public class Account
{
public string Email { get; set; }
public bool Active { get; set; }
public DateTime CreatedDate { get; set; }
public Account()
{
Email = Email.ToUpper();
}
}
按钮单击事件
string json = @"{
'Email': 'james@example.com',
'Active': true,
'CreatedDate': '2013-01-20T00:00:00Z'
}";
Account account = JsonConvert.DeserializeObject<Account>(json);
MessageBox.Show(account.Email);//printed james@example.com
private string _email;
public string Email
{
get{
return _email;
}
set
{
this._email = value.ToUpper();
}
}