Creating C# class from Json

Actually, this is not that hard when you use the JsonProperty attribute

public class Class1    {
        public string Icao { get; set; } 

        public string Iata { get; set; } 

        public string Name { get; set; } 

        public string City { get; set; } 

        public string State { get; set; } 

        public string Country { get; set; } 

        public int Elevation { get; set; } 

        public double Latitude { get; set; } 

        public double Longtitude { get; set; } 

        public string Tz { get; set; } 


    public class Root    {
        public Class1 GeoDatAK{ get; set; } 

        public Class1 GeoDatAL { get; set; } 

to instantiate it do:

Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse); 

I personally use the properties to shorten the Json send between services and mobile applications. this becomes especially important when using obfuscation as obfuscated classes that are not public should get renamed.

Look at [JsonConstructor] annotation for internal constructors and use parameters named with the properties

in your class this would be:

internal Class1(string icao)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top