我试图序列化KeyValue“ Array”,以通过HTTP通过PUT将其发送到我的asp.net网络服务器。
Angular中的函数如下:
SortAboutUs(data : KeyValue<number,number>[]) {
this.dataTransmitter.Put(this.apiUrl+'/api/aboutus/sort',data);
}
如果我调试以下数据容器,则它看起来像这样:
.net核心Web服务器的控制器中具有以下内容
[HttpPut("[action]")]
public actionResult<bool> Sort(IList<keyvaluepair<int,int>> dto)
{
return Ok(_aboutUsService.Sort(dto));
}
但是,当我尝试通过PUT发送时出现以下错误:
The JSON value could not be converted to System.Collections.Generic.List`1[System.Collections.Generic.keyvaluepair`2[System.Int32,System.Int32]]. Path: $[0] | LineNumber: 0 | BytePositionInLine: 8.
奇怪的是,我已经在.net核心的另一个旧版本中使用了相同的技术,并且似乎一切正常。
我还注意到,自.net core 3.1以来,C#中的KeyValue更改为keyvaluepair,但在较旧版本的.net core中,它是KeyValue。
这与我的相关错误有关吗?
又如何从Angular序列化KeyValue,以便我的Web服务器可以读取它?