public class PayeeContactDetails
{
//[JsonProperty("id")]
//[DefaultValue("")]
//public int ID { get; set; }
[JsonProperty("contact_name")]
[DefaultValue("")]
public string ContactName { get; set; }
[JsonProperty("contact_email")]
[DefaultValue("")]
public string ContactEmail { get; set; }
........
........
}
public class PayeeContactGroup
{
[JsonProperty("payee_contacts")]
public List<PayeeContactDetails> PayeeContact { get; set; }
}
在这里,我从api响应中获取数据,在完成所有页面后,我需要一次将所有数据发送到DB
PayeeContactGroup payeeContactDetails = new PayeeContactGroup();
var response = httpClient.GetAsync(uri).Result;
if (response.IsSuccessStatusCode)
{
string data = response.Content.ReadAsStringAsync().Result;
var payeeContactGroupDetails = JsonConvert.DeserializeObject<PayeeContactGroup>(data);
if(payeeContactGroupDetails.PayeeContact != null && payeeContactGroupDetails.currentPage == 1)
{
payeeContactDetails.PayeeContact = payeeContactGroupDetails.PayeeContact.ToList();
}
else if(payeeContactGroupDetails.PayeeContact != null && payeeContactGroupDetails.currentPage > 1)
{
payeeContactDetails.PayeeContact.AddRange(payeeContactGroupDetails.PayeeContact); // error at this line
}
.......
......
}
但我在
这条线
“payeeContactDetails.PayeeContact.AddRange(payeeContactGroupDetails.PayeeContact);”
错误:“对象引用未设置为对象”
非常感谢