Newtonsoft.Json无法创建和填充列表类型

时间:2014-12-12 18:19:37

标签: c# serialization json.net deserialization

我有一个模特:

[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 = "";
}

只是尝试序列化和反序列化:

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

我收到错误:

     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":[]}

我知道我错过了一些东西,但我真的能理解......

0 个答案:

没有答案