I'm working on the following JSON data and when trying to serialize an object I get the error
Object reference not set to an instance of an object
Here are my classes:
    public class Hotel
    {
        [JsonProperty("Hotel")]
        public Address1 Address1 { get; set; }
    }
    public class Address1
    {
        public string GuestData { get; set; }
        public string GuestName { get; set; }
        public string GuestSurName { get; set; }
    }
And I tried to serialize this way:
List<Hotel> Hotel = new List<Hotel>();
Hotel e = new Hotel();
e.Address1.GuestName = "Kevin";
e.Address1.GuestSurName = "Jones";
Hotel.Add(e);
string json = JsonConvert.SerializeObject(Hotel, Formatting.Indented);
textBox1.Text = json;
I put the code in Form_Load and I get the error
Additional information: Object reference not set to an instance of an object
What am I doing wrong?
 
     
    