0

i would want to deserialize the json object. But for "Email", there are brackets outside of it. In Account class, it does not allow to put "[Email]" but only "Email". Anyone could help on this? thanks.

Class:

public class Account
{
    public string Email { get; set; }
    public bool Active { get; set; }
    public DateTime CreatedDate { get; set; }
}

The JSON:

{
  '[Email]': 'james@example.com',
  'Active': true,
  'CreatedDate': '2013-01-20T00:00:00Z',
}

How I deserialize:

Account account = JsonConvert.DeserializeObject<Account>(json);

Console.WriteLine(account.Email);
U.K.N
  • 25
  • 1
  • 6

1 Answers1

6

You can manually change the serialize and deserialize property name by adding the [JsonProperty] attribute.

[JsonProperty("[Email]")]
public string Email { get; set; }
Orel Eraki
  • 11,940
  • 3
  • 28
  • 36