Click or drag to resize
Json.NETJsonConstructorAttribute
 

This sample uses the JsonConstructorAttribute to specify that a constrctor should be used to create a class during deserialization.

Sample
Types
 1public class User
 2{
 3    public string UserName { get; private set; }
 4    public bool Enabled { get; private set; }
 5
 6    public User()
 7    {
 8    }
 9
10    [JsonConstructor]
11    public User(string userName, bool enabled)
12    {
13        UserName = userName;
14        Enabled = enabled;
15    }
16}
Usage
1string json = @"{
2  ""UserName"": ""domain\\username"",
3  ""Enabled"": true
4}";
5
6User user = JsonConvert.DeserializeObject<User>(json);
7
8Console.WriteLine(user.UserName);
9// domain\username