I have a JsonDocument
which I need to deserialize into a known model.
The problem with deserializing is that I am not getting the inner lists filled out.
How do I go about fixing that?
My JSON looks like this:
{
"version": 1,
"sections": [
{
"label": "General Information",
"fields": [
{
"order": 1,
"internalName": "a"
},
{
"order": 2,
"internalName": "b"
},
{
"order": 3,
"internalName": "c"
}
]
}
]
}
This is stored in a JsonDocument
that I want to dererialize to a model that I have defined like this:
public class UILayout
{
public long Version { get; set; }
public Section[] Sections { get; set; }
}
public class Section
{
public string Label { get; set; }
public Field[] Fields { get; set; }
}
public class Field
{
public long Order { get; set; }
public string InternalName { get; set; }
}
But when I deserialize it, I notice that UILayout.Sections
property is empty?
var serializedLayout = JsonSerializer.Deserialize<UILayout>(Layout.UILayout.RootElement.ToString());
Why is it empty? How do I deserialize the JSON to a defined model?