I have this simple model in an ASP.NET WebAPI 2 application:
public class Model {
public int ID { get; set; }
public Dictionary<string, string> Dic { get; set; }
}
When it gets serialized, the output is:
{
"ID": 0,
"Dic": {
"name1": "value1",
"name2": "value2"
}
}
I searched the problem, but it seems most people need this serialization:
{
"ID": 0,
"Dic": [{
"Key": "name1",
"Value": "value1"
}]
}
And all solutions out there are resolving to that kind of serialization. But what I'm looking for is to serialize the dictionary into this format:
{
"ID": 0,
"Dic": [{
"name1": "value1"
}, {
"name2": "value2"
}]
}
In other words, I want to serialize it into an array of objects containing one "name1": "value1"
pair each. Is there any way to do that? Or I should be looking for another type?