Home > DeveloperSection > Forums > Setting a variable name as a type
john rob

Total Post:108

Points:756
Posted on    December-23-2013 2:33 AM

 C# C# 
Ratings:


 1 Reply(s)
 667  View(s)
Rate this:

I am deserializing a json object from a third party API. One of the Objects properties is a variable called "checked". In c#.net 'checked' is a type. Is there anyway to overcome this.

Im using Newtonsoft Json.net to do the deserializing.

Nothing special about the class,

public class item{

  public bool checked;

}



Pravesh Singh

Total Post:411

Points:2881
Posted on    December-23-2013 5:02 AM

Hi John,

While @nemesv's answer is correct and will work fine, I just wanted to mention that there is another alternative if you are using Json.Net. You could use a JsonProperty attribute to map your class property to the JSON property such that they can have different names. For example:

public class item

{

    [JsonProperty("checked")]

    public bool IsChecked { get; set; }

}


Don't want to miss updates? Please click the below button!

Follow MindStick