Newtonsoft.Json Cannot create and populate list type

我只是一个虾纸丫 提交于 2019-12-12 15:49:13

问题


I have a model:

[Serializable]
public class User
{
    public string UserID { get; set; }
    public string UserName { get; set; }
    public string Password { get; set;}

    public bool isLoggedIn { get; set; }

    public CookieCollection Cookies { get; set; }

    [NonSerialized]
    public string Response = "";
}

Just trying to serialize and deserialize:

  string str = Newtonsoft.Json.JsonConvert.SerializeObject(u, typeof(User), settings);
  User us = Newtonsoft.Json.JsonConvert.DeserializeObject<User>(str);

I am getting an error:

     Cannot create and populate list type System.Net.CookieCollection. Path 'Cookies', line 1, position 92.

Json string:

    {"UserID":null,"UserName":"nazarkin659","Password":"Hakers659","isLoggedIn":true,"Cookies":[]}

I know that I am missing something, but I can' really understand what...

来源:https://stackoverflow.com/questions/27449717/newtonsoft-json-cannot-create-and-populate-list-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!