I have the following dictionary:
[JsonProperty("Simulations")]
public IDictionary<int, Simulation> Simulations { get; set; }
When I'm sending my data to the front I send it as an object:
"simulations": {
"02": {
"rachatBrut": 542,
"montantPercu": 250,
},
"52": {
"rachatBrut": 400,
"montantPercu": 385,
},
}
I want to send only the values of the dictionary as an array:
"simulations": [
{
"rachatBrut": 542,
"montantPercu": 250,
},
{
"rachatBrut": 400,
"montantPercu": 385,
}
]
You could either add another property and use [JsonIgnore] on the one u have right now. To make the new one an array just call .ToArray() on the Dictionary. Or you can write yourself an own CustomJsonConverter for this behavior.
For your specific case this would produce an array like the one u need:
Simulations.Select(k => k.Value).ToArray();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With