在对下面的类进行反序列化时,我遇到了一个null异常:
[Serializable]
public class myClass
{
public IList<string> ResidentialAddressToPrint
{
get
{
var list = new List<string>();
if (!string.IsNullOrWhiteSpace(ResidentialAddress.AddressLine1))
list.Add(ResidentialAddress.AddressLine1);
if (!string.IsNullOrWhiteSpace(ResidentialAddress.AddressLine2))
list.Add(ResidentialAddress.AddressLine2);
if (!string.IsNullOrWhiteSpace(ResidentialAddress.Suburb))
list.Add(ResidentialAddress.Suburb);
if (!string.IsNullOrWhiteSpace(ResidentialAddress.State))
list.Add(ResidentialAddress.State);
if (!string.IsNullOrWhiteSpace(ResidentialAddress.Postcode))
list.Add(ResidentialAddress.Postcode);
return list;
}
}
[Serializable]
public class RegisterRebateAddressModel
{
public string AddressLine1 { get; set; }
public string AddressLine2 { get; set; }
public string Suburb { get; set; }
public string State { get; set; }
public string Postcode { get; set; }
}
*Newtonsoft.Json.JsonSerializationException: Error getting value from 'myClass'. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at myClass.get_ResidentialAddressToPrint()*
有人可以在下面澄清:
newtonsoft是否需要强制设置属性?
还注意到私人套餐失败了;属性。是这个功能的设计。
解决此问题的最佳方法是什么,因为我们有很多没有setter的属性。