I got this strange API response from external service:
{
"Columns": {
"1": {
"Fuels": [
"1",
"10",
"4",
"4"
]
},
...
"6": {
"Fuels": [
"1",
"4",
"10"
]
}
}
}
By default, all converters (json -> to csharp model) does models like this:
public class _1
{
public List<string> Fuels { get; set; }
}
public class _2
{
public List<string> Fuels { get; set; }
}
public class _3
{
public List<string> Fuels { get; set; }
}
public class _4
{
public List<string> Fuels { get; set; }
}
public class Columns
{
public _1 _1 { get; set; }
public _2 _2 { get; set; }
public _3 _3 { get; set; }
public _4 _4 { get; set; }
}
But I want something like this:
public class Column
{
public string Number { get; set; }
public List<string> Fuels { get; set; }
}
I think it's a side developers fault with Json
serialization, because Columns
should be an Array
, but it's an Objects :(
I need to somehow convert this to Array, maybe it is some Newtonsoft
or default .NET Json converter attributes
or something to do that without writing custom deserializer?
I'm using .NET 6.