WebApi: 将 List<int> 变量正确放入对象类型的 属性

WebApi: Put List<int> variable into the property of object type properly

我有一个 object 类型的模型 属性,显然可以从那里输出任何类型的值。我的任务放在那里 List<int> 值,但是当我按原样放置时,或者例如 list.Cast<object>() 我在 [= 之后的模型字段中得到像 [[1], [2], [255]] 这样的数组数组33=] 控制器输出序列化。

重要,我无法更改 属性 类型。有什么建议吗?

这是此 属性 的代码。 DocumentChildIdsBoolValue 等是此模型中的其他属性 class:

public object ResolvedValue =>
            FieldType == CustomFieldType.Document ? DocumentChildIds :
            FieldType == CustomFieldType.Boolean ? BoolValue :
            FieldType == CustomFieldType.Date ? DateValue.HasValue ? DateValue.Value.ToShortDateString() : "" :
            FieldType == CustomFieldType.Integer ? IntValue :
            FieldType == CustomFieldType.DB_LOOKUP 
            || FieldType == CustomFieldType.LOOKUP
            || FieldType == CustomFieldType.MULTI_LOOKUP
            || FieldType == CustomFieldType.LOOKUP_TO_CLIENT ? (object) LookupId : StringValue; //by default all the rest types having string value

其中 DocumentChildIds 具有 List<int> 类型和输入 {1,2,3} 我在 Json 中得到 [[1],[2],[3]] 而不是 [1,2,3]

我的错误。这个 属性 值在解析 where ToList() 调用它之后通过 Group by 并成为数组的数组。

 var arrayValueFields = documentComposite
                .Where(i => ArrayValueResultTypes.Contains(i.FieldType))
                .GroupBy(i => i.FieldId)
                .Select(g => new DocumentItemFieldValueDto
                {
                    FieldId = g.Key,
                    FieldType = g.Select(i => i.FieldType).FirstOrDefault(),
                    FieldCaption = g.Select(i => i.FieldCaption).FirstOrDefault(),
                    FieldValue = g.Select(i => i.ResolvedValue).ToList()
                  ...
                 }

不要重蹈我的覆辙