我将从客户端 Web 应用程序发送一个 Json 数组到 ASP.NET WebAPI。例如,
{
"SurveyId":3423,
"CreatorId":4235,
"GlobalAppId":34,
"AssociateList":[
{"AssociateId":4234},
{"AssociateId":43},
{"AssociateId":23423},
{"AssociateId":432}
],
"IsModelDirty":false,
"SaveMode":null
}
这里的“Associate List”是一个JSON数组,通常会自动序列化为List<>对象。
使用以下代码,我将响应发布到WebApi:
public IEnumerable<Associate> Post(ResponseStatus responseStatus)
{
return this.responsestatusrepository.ResponseStatusCheck(responseStatus);
}
ResponseStatus类如下所示。
public class ResponseStatus : AppBaseModel
{
public int SurveyId { get; set; }
public int CreatorId { get; set; }
public int GlobalAppId { get; set; }
public List<Associate> AssociateList { get; set; }
}
作为我的代码分析纠正的一部分,我已经将List<>更改为Collection<>。
例如:public Collection<Associate> AssociateList { get; set; }
但是,在使用集合而不是列表时,它总是得到一个null值。这是否有任何特定的原因?