Próbuje zserializować json'a. W tym celu stworzyłem klasę Car
class Car
{
public Id id { get; set; }
}
public class Id
{
public string brand { get; set; }
public string model { get; set; }
public string year { get; set; }
public string r_no { get; set; }
public string owner { get; set; }
}
Później, chce wykonać wspomnianą operację po kliknięciu guzika
private void saveButton_Click(object sender, EventArgs e)
{
Car Auto1 = new Car();
Id id = new Id();
Auto1.id.brand = textBox1.Text;
Auto1.id.model = textBox2.Text;
Auto1.id.year = textBox3.Text;
Auto1.id.r_no = textBox4.Text;
Auto1.id.owner = textBox5.Text;
string json = JsonConvert.SerializeObject(Auto1);
MessageBox.Show(json);
}
Cały czas dostaje nullpointer exception ale nie wiem za bardzo dlaczego. Obiekt jest stworzony poprawnie wg mnie? Inicjuje go przy przypisaniu do Textboxa?