2

I have an JSON which contains a property that starts with $ sign.

class Program
    {
        static void Main(string[] args)
        {
            var my_jsondata = @"{ '$type': 'Psd' }";

            var result = JsonConvert.DeserializeObject<ClassToDeserialize>(my_jsondata);
            Console.WriteLine(result.Type);
            Console.ReadKey();
        }
    }

I want to deserialize this json to my class:

public class ClassToDeserialize
{
    [JsonProperty(PropertyName = "$type", Order = -2)]
    public Constants.Party? Type { get; set; }

    
}

And here is my enum

[JsonConverter(typeof(StringEnumConverter))]
public enum Party
    {
        [EnumMember(Value = "Psd")]
        Psd,
        [EnumMember(Value = "Pnl")]
        Pnl
    }

My problem is with that $type sign because if I change it everything works fine by deserialization but if it stays than the mapping does not take place. Now result.Type will be null and nothing appears in Console. Could you please help me.

Liam
  • 27,717
  • 28
  • 128
  • 190

0 Answers0