【发布时间】:2015-08-24 14:07:14
【问题描述】:
这是我的 json
{
"accessType":"Grant",
"spaces":[{"spaceId":"5c209ba0-e24d-450d-8f23-44a99e6ae415"}],
"privilegeId":"db7cd037-6503-4dbf-8566-2cca4787119d",
"privilegeName":"PERM_RVMC_DEV",
"privilegeDescription":"RVMC Dev",
"privilegeType":"Permission"
}
这是我的课:
public class ProfilePrivilege
{
public AccessType AccessType { get; set; }
public Guid PrivilegeId { get; set; }
public string PrivilegeName { get; set; }
public string PrivilegeDescription { get; set; }
public PrivilegeType PrivilegeType { get; set; }
public List<Guid> spaces;
}
当空格数组不为空时,我得到一个反序列化错误。我可以通过简单地为 Guid 创建一个包装类来解决这个问题
public class Space
{
public Guid spaceId;
}
然后我可以在我的特权课程中使用List<Space> 而不是List<Guid>,这一切都很好。但我想知道是否有更好的方法来做到这一点,因为我不想为此而有一个冗余的包装类。那么有没有什么简单的方法可以在不为我的 Privilege 类型对象编写自定义反序列化程序的情况下解决这个问题?
顺便说一句,我正在使用 JSON.Net 反序列化。
【问题讨论】:
标签: c# json serialization json.net