我正在尝试将商品添加到用于以下目的的列表中;
public class Reason
{
[JsonProperty("code")]
public int Code { get; internal set; }
}
public class Item
{
[JsonProperty("Id")]
public int Id { get; set; }
[JsonProperty("quantity")]
public int quantity { get; set; }
[JsonProperty("reason")]
public Reason reason { get; set; } = new Reason();
}
public class RootObject
{
[JsonProperty("dropOff")]
public DropOff dropOff { get; set; } = new DropOff();
[JsonProperty("providerId")]
public int providerId { get; set; }
[JsonProperty("orderReference")]
public string orderReference { get; set; }
[JsonProperty("returnMethodId")]
public int returnMethodId { get; set; }
[JsonProperty("items")]
public List<Item> items { get; set; } = new List<Item>();
}
root.items.Add(new Item { Id = 8675072, quantity = 1, Reason.Code = 2 });
当我尝试添加Reason.Code时,出现以下错误,
非字段,方法或属性需要对象引用。
我需要在哪里初始化以将Reason.Code添加到列表中?
root.items.Add(new Item { Id = 8675072, quantity = 1, reason = { Code = 2 }})
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句