我正在从客户端Web应用程序发送一个Json数组到asp.net webapi.例如,
{
"SurveyId":3423,
"CreatorId":4235,
"GlobalAppId":34,
"AssociateList":[
{"AssociateId":4234},
{"AssociateId":43},
{"AssociateId":23423},
{"AssociateId":432}
],
"IsModelDirty":false,
"SaveMode":null
}
Run Code Online (Sandbox Code Playgroud)
这里的Associate List是一个JSON数组,通常它会自动序列化为List <>对象.
使用下面的代码,我将响应发布到WebApi
public IEnumerable<Associate> Post(ResponseStatus responseStatus)
{
return this.responsestatusrepository.ResponseStatusCheck(responseStatus);
}
Run Code Online (Sandbox Code Playgroud)
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; }
}
Run Code Online (Sandbox Code Playgroud)
我已将List <>更改为Collection <>,作为我的代码分析更正的一部分.即public Collection<Associate> AssociateList { get; set; }
但是当我们使用集合而不是List时,它总是得到一个空值.这有什么具体原因吗?