服务器有一个控制器,它具有以下方法:
[HttpPost]
public bool Register([FromBody]SalesPoint salesPoint)
{
...
}
SalesPoint是这样描述的:
public class SalesPoint
{
public string Name { get; set; }
public Dictionary<TerminalType, List<Terminal>> Terminals { get; set; } = new Dictionary<TerminalType, List<Terminal>>();
}
public enum TerminalType
{
Type1 = 1,
Type2 = 2
}
public class Terminal
{
public TerminalType Type { get; set; }
public string Code { get; set; }
}
客户端形成正确的 JSON 并将其发送到服务器,但参数salesPoint为 null。
通过 PostMan 进行测试时,该方法不接受此类 JSON(正确):
{
"Name": "Test",
"Terminals": [{
"Key": 1,
"Value": [{
"Type": 1,
"Code": "78-343002"
}]
}]
}
但是如果你扔掉字典的 JSON 并像这样发送它:
{
"Name": "Test"
}
然后它正常反序列化。问题是什么?


