c# - c#没有为DTO属性中的类型定义无参数构造函数
问题描述
我有一个问题,我有一个使用 RestClient 获取信息的简单操作,代码如下所示:
var client = new RestClient(RestClientBaseUrl);
IRestResponse request = client.Execute(new RestRequest("Application/GetApplications", Method.GET));
IEnumerable<DTO.Application> response = new JsonDeserializer().Deserialize<IEnumerable<DTO.Application>>(request);
此模型的 DTO 如下所示:
public class Application
{
public int? Id { get; set; }
public string Name { get; set; }
public GetSystem[] Systems { get; set; }
}
对于系统,它看起来像:
public class GetSystem : SystemTemplate
{
public int Id { get; set; }
public SystemState SystemState { get; set; }
}
系统模板
public abstract class SystemTemplate
{
public string Name { get; set; }
public string IpAddress { get; set; }
public int Port { get; set; }
}
和系统状态:
public class SystemState
{
public int? Id { get; set; }
public byte MaintenanceMode { get; set; }
public string LastCommunicationTimestamp { get; set; }
public int SystemId { get; set; }
}
现在的问题是当我反序列化 Json 时,我得到:
System.MissingMethodException : No parameterless constructor defined for type 'DS.Models.DTO.GetSystem[]'.
可能是什么问题呢?
解决方案
您需要在 GetSystem 类中添加一个空构造函数。
推荐阅读
- gmail - Chronograf 为 Gmail 设置警报
- oracle-apex - Oracle APEX - 如果未对表单进行任何更改,则会显示成功消息
- r - 使用大数据集训练 R 插入符号模型
- django - 从 IIS 中托管的 Flask 应用程序打开服务器中的浏览器不起作用
- python - 将 pandas 系列中的 -1 替换为唯一值
- spring - hibernate envers 审计即使没有变化
- scala - Scala isDefined 得到 None 值,即使它有值
- pandas - 熊猫 iat:vscode 与 jupiterlab
- java - 动态生成字母序列
- python - 将数据框中的行值映射到熊猫中的列值?