'Deserializing json property with attribute returns null...C#

Using NewtonSoft to do the deserializing.

I have the following JSON string

{\"PK\":\"[email protected]\",\"SK\":\"read\",\"Role\":\"RLE#readonly\"}

I want to deserialize it to the following class:

public class UserDto
 {

    [JsonPropertyName("PK")]

    public string Email { get; set; }

    public string SK { get; set; }

     public string Role { get; set; }

 }

When i run the folllowing:

var json = "{\"PK\":\"[email protected]\",\"SK\":\"read\",\"Role\":\"RLE#readonly\"}";
var dto = JsonConvert.DeserializeObject<UserDto>(json);

All properties have values except Email which is null. I have the JsonProperty attribute but its still not working. How do I deserialize the PK JSON property to my Email C# property?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source