将DeserializeObject <object>转换为实体对象不起作用

时间:2018-04-10 12:50:57

标签: serialization deserialization

我想将反序列化的对象转换为像这样的实体对象:

 item.Data = JsonConvert.DeserializeObject<Object>(reader["Data"].ToString());
 User user = item.Data as User;

但在第二行中,用户设置为null,因为item.Data无法转换为用户,但以下行有效:

item.Data = JsonConvert.DeserializeObject<User>(reader["Data"].ToString());

为什么?

注意:用户类是这样的:

 [Serializable]
public class User
{

    private string fullName, userName;
    private Enumes.UserType userType;
    private Int64 userCode;
    private Int32 userID;
    private string userTypeDesc;
    private string lastLoginIP;
    private string lastLoginTime;
    private List<Enumes.UserRole> userRole;
    private List<UserAccessLevel> userAccessLevel;
    private string mobilePhone;
    private string codeMelli;
    private string bDate;        
    private Enumes.UserCurrentStatus currentStatus;
    private string currentIPAddress;
 ...}

UserAccessLevel也是Serializable。

0 个答案:

没有答案