//存在默认构造函数(无论显示还是隐式)
public class Website
{
public string Url { get; set; }
public Website()
{
//todo...
}
public Website(Website website)
{
//todo...
}
public Website(int value)
{
//todo...
}
}
string json = @"{'Url':'http://www.google.com'}";
try
{
//当反序列化对象存在默认构造函数(无论显示还是隐式)时,反序列化会只调用默认构造函数
var web = JsonConvert.DeserializeObject<Website>(json);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
// Value cannot be null.
// Parameter name: website
}
JSON.NET学习(9)--反序列化对象构造函数处理(一)
最新推荐文章于 2021-11-02 14:57:49 发布