I apologize if this is a duplicate, but none of the related answers I saw had JSON similar to the format I'm dealing with. I'm consuming an API response that has the following JSON format:
{
"KnownPropName": [
{
"DynamicPropName": [
{
"KnownProp1": "value",
"KnownProp2": "value"
},
{
"KnownProp1": "value",
"KnownProp2": "value"
}]
}]
}
I know the names of the parameters for each object except for "DynamicPropName", which I cannot know ahead of time.
I have the below classes setup:
private class TestResponse
{
public TestOuter[] KnownPropName { get; set; }
}
private class TestOuter
{
public TestInner[] TestInners { get; set; }
}
private class TestInner
{
public string KnownProp1 { get; set; }
public string KnownProp2 { get; set; }
}
If I change the property name "TestInners" to "DynamicPropName" everything deserializes with no issues. However, since I will not know the actual property name ahead of time I need to somehow have this work when "TestInners" does not match the corresponding property name.
I don't believe I can use a dictionary because the arrays don't contain string keys, but instead objects.
I know I can use a custom converter to solve this, but I'd like to know if it is at all possible without using one. Is there a way to have JSON deserialize based on the order of the parameters instead of depending on the name?