JsonProperty c#将字典值序列化到数组中

JsonProperty c#将字典值序列化到数组中,c#,json,asp.net-core,deserialization,C#,Json,Asp.net Core,Deserialization,我有以下字典: [JsonProperty("Simulations")] public IDictionary<int, Simulation> Simulations { get; set; } 通缉行为 我只想将字典的值作为数组发送: "simulations": [ { "rachatBrut": 542, "montantPercu": 250, }, {

我有以下字典:

   [JsonProperty("Simulations")]
    public IDictionary<int, Simulation> Simulations { get; set; }
通缉行为 我只想将字典的值作为数组发送:

   "simulations": [
       {
            "rachatBrut": 542,
            "montantPercu": 250,
       },
       {
            "rachatBrut": 400,
            "montantPercu": 385,
       }
    ]

您可以添加另一个属性,并在您现在拥有的属性上使用[JsonIgnore]。要使新的数组成为数组,只需在字典上调用.ToArray()。 或者你也可以为这种行为写一本自己的书

对于您的特定情况,这将生成一个与您需要的阵列类似的阵列:

Simulations.Select(k => k.Value).ToArray();

JsonIgnore
现有属性。创建一个新的只读属性,用于在JSON中投影所需的数组。它生成一个包含KeyValuePair对象的数组。如果你只想要你需要的值,请在选择之前使用。谢谢。我最终把我的字典转换成了一系列的模拟
Simulations.Select(k => k.Value).ToArray();