Currently I have a JSON body that I would like to deserialize into a list of objects in C#. The JSON looks very similar to this:
{
"123": {
"id": "123",
"description": "Element 1",
...
},
"456": {
"id": "456",
"description": "Element 2",
...
},
...
}
My current structure is as follows:
class FooList
{
public Dictionary<int, Foo> Foos { get; set; }
}
class Foo
{
public int id { get; set; }
public string description { get; set; }
}
and utilising NewtonSoft I am attempting the following:
// json = string representation of json data
JsonConvert.DeserializeObject<FooList>(json);
This doesn't work. I have managed to deserialize single instances of Foo with the previous line of code, but I am unsure how I can handle the process when the JSON doesn't have a set root element and comprises a list of objects with dynamic root elements.
Apologies if this question has been answered previously, either I am using incorrect language to describe the issue or the answer doesn't seem to exist.
Edit: "This doesn't work" equates to returning an instance of FooList with Foos as null.