I have the following class, whose fields I want to populate by deserializing a JSON file:
public class FirstThreeRandomProperties
{
public List<string> extras1;
public List<string> extras2;
public List<string> extras3;
}
Unfortunately, the JSON I wish to deserialize has properties with variable names. I want to be able to deserialize the following JSON:
{
'unknownName1': [ "A" ],
'unknownName1': [ "A", "B", "C" ]
}
As you can see, the names of the properties are random, but the properties are always arrays of strings. I want to map the first three to the variables in ThreeExtras and throw the rest away (if there are more than three). I want this to be mapped to:
{
'extras1': [ "A" ],
'extras2': [ "A", "B", "C" ],
'extras3': null
}
Is this possible?
EDIT: FirstThreeRandomProperties is actually a member of another object like so:
public class ParentObject
{
// Other properties
public FirstThreeRandomProperties extraProperties;
}
So I would prefer a solution that easily lets me fill ParentObject with extraProperties getting its values as described above.