so I have this class:
public class CheckTweetSingle
{
public int item1 { get; set; }
public int item2 { get; set; }
}
I get a json string that I am converting the values into item1 and item2.
is it possible to change the name of item1 to chairs and item2 to tables, so I can access them via checkTweet.chair instead of checkTweet.item2?
I cannot change the way the json string is coming..
thank you.
You just need to decorate your class properties with the JsonProperty attribute like this
public class CheckTweetSingle
{
[JsonProperty("item1")]
public int chairs { get; set; }
[JsonProperty("item2")]
public int tables { get; set; }
}
This attribute tells to your json library that when deserializing json data the entry with the name "item1" should be assigned to the property chairs. Viceversa if you ever need to serialize that class the value of the property chairs goes to the "item1" entry in the json output
Note: I assume you are using Newtonsoft Json.NET as your json library