字典的序列化/反序列化不支持字典,键必须是字符串或对象

nik*_*nik 10 .net c# serialization dictionary

当我尝试在Ajax中反序列化此Dictionary时,我有这个方法将Dictionary作为JsonResult返回我收到此错误:

这是我在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);
}
Run Code Online (Sandbox Code Playgroud)

这是错误:

键入'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]]',键必须是字符串或对象.

小智 12

这是你的字典: Dictionary<int, AmItem>

这是你的字典应该是: Dictionary<string, AmItem>