-2

我需要有 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"));

这也给了我错误。

4

1 回答 1

1

试试(我附近没有编译器)

var  sampleList = new HashSet<Result>(rootoject.result.Where(item
            => item.status == "approved")).ToList();
var sampleRootObject = new RootObject();
sampleRootObject.result = sampleList; // The setter needs to be made public
approvedList.Add( sampleRootObject);
于 2013-10-09T06:27:26.877 回答