小编Sun*_*nil的帖子

JSON数组正在转换为通用列表,但不转换为通用集合.为什么?

我正在从客户端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时,它总是得到一个空值.这有什么具体原因吗?

collections json list asp.net-web-api

6
推荐指数
1
解决办法
455
查看次数

标签 统计

asp.net-web-api ×1

collections ×1

json ×1

list ×1