【发布时间】:2021-12-19 21:27:35
【问题描述】:
确切的错误是Cannot create and populate list type System.Collections.ICollection. Path'[0].assocPosition.assocJobtitle.employees''
我有这个方法
public static ArrayList Get<T>(string url)
{
using (var response = _httpClient.GetAsync(baseUrl + url).Result)
{
if (response.IsSuccessStatusCode)
{
var customerJsonString = response.Content.ReadAsStringAsync().Result;
var list = JsonConvert.DeserializeObject<List<T>>(customerJsonString);
var arrayList = new ArrayList(list.Count);
foreach (T item in list)
{
arrayList.Add(item);
}
return arrayList;
}
}
return null;
}
在放置断点后我发现问题在于对象没有正确反序列化。
public static ArrayList EmployeeAssignmentFinder_FindAll()
{
return HttpCaller.Get<EmployeeAssignment>("WorkflowEngine/EmployeeAssignmentFinder_FindAll");
}
控制器内部的HttpGet:
[HttpGet("WorkflowEngine/EmployeeAssignmentFinder_FindAll")]
public IActionResult WorkflowEngineEmployeeAssignmentFinder_FindAll()
{
return Ok(_engine.VC.EmployeeAssignmentFinder_FindAll());
}
EmployeeAssignment 类有内部:
private Position m_Position;
public Position AssocPosition
{
get { return m_Position; }
set { m_Position = value; }
}
职位类有内部:
private Jobtitle m_AssocJobtitle;
public Jobtitle AssocJobtitle
{
get { return m_AssocJobtitle; }
set { m_AssocJobtitle = value; }
}
而 Jobtitle 类有里面:
private ICollection m_Employees;
public ICollection Employees
{
get{ return m_Employees; }
set { m_Employees = value;}
}
从ICollection 到ArrayList 可能存在冲突。
【问题讨论】:
-
获取进入您的 Web 服务的 json 并将其粘贴到 QuickType.io 以获得一组适用于它的类..
标签: c# arraylist json.net icollection