I use an API that has JSON like this:
{
id: 1,
firstName: "test",
lastName: "user",
field26461: "abc123"
}
I have this C# class
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
}
They continually add these custom fields. So after shipping my code, there may be a "field32123" in there with some value.
How can I make my code capture these extra fields?
Could I update my class to the following, and somehow have all the fields and their values go into a dictionary?
{
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public Dictionary<string,string> ExtraFields { get; set; }
}
XML has an [XmlAnyElement] attribute that you can use to capture such extra fields.