The dictionary is not supported for serializing / deserializing the dictionary, keys must be strings or objects

I have this method that returns a dictionary as JsonResult when I try to deserialize this dictionary in Ajax. I get this error:

This is my method in MVC:

[HttpPost]
public JsonResult GetCalculateAmortizationSchedule()
{
      var data =.....
      var httpClient = new HttpClient();
      var response = httpClient.PostAsJsonAsync("http://localhost:62815/v1/APR/CalculateAmortizationSchedule", data).Result;
      var returnValue = response.Content.ReadAsAsync<Dictionary<int, AmItem>>().Result;
      return Json(returnValue);
}

This is mistake:

Enter "System.Collections.Generic.Dictionary`2 [[System.Int32, mscorlib, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089], [ConnectionMappingSample.Models.AmItem, ConnectionMappingSample, Version = 1.0. 0.0, Culture = neutral, PublicKeyToken = null]] 'is not supported for serialization / deserialization of the dictionary, the keys must be strings or objects.

+4
source share
1

: Dictionary<int, AmItem>

: Dictionary<string, AmItem>

+7

Source: https://habr.com/ru/post/1677786/


All Articles