我需要有 2 个列表(列表 A 和列表 B),两个列表的数据源都是 JSON 数组对象,列表 A 包含来自 JSON 响应的所有记录,列表 B 包含它的子集,基于状态类型的对象。这是我到目前为止所拥有的:
public class Result
{
public int request_id { get; set; }
public string createdTime { get; set; }
public string status { get; set; }
}
public class RootObject
{
public List<Result> result { get; set; }
}
我正在使用 JSON.NET 解析它并填充列表 A
var responseString = await response.Content.ReadAsStringAsync();
RootObject rootoject = JsonConvert.DeserializeObject<List<RootObject>>(responseString)[0];
ListBox1.ItemsSource = rootoject.result;
我在这里根据状态查询记录列表
HashSet<Result> sample = new HashSet<Result>(rootoject.result.Where(item
=> item.status == "approved"));
List<RootObject> approvedlist = new List<RootObject>();
**approvedlist.Add(sample); Getting error here cannot convert from hashset to Rootobject**
我试过了
RootObject sample=new HashSet<Result>(rootoject.result.Where(item
=> item.status == "approved"));
这也给了我错误。