2013-10-09 34 views
-2

我需要有2个列表(列表A和列表B),列表的数据源都是JSON数组对象,列表A包含来自JSON响应和列表的所有记录B包含它的一个子集,它基于对象的状态类型。这是我到目前为止有:将对象添加到列表中c#-windows phone

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")); 

这也给我错误。

+0

嗯,是 - 你想一个HashSet的''添加到列表'' - 你有什么期待* *是去做? –

+0

RootObject sample = new HashSet (rootoject.result.Where(item => item.status ==“approved”));这使我有一个错误..我不知道如何得到这个工作.. –

+0

你不能将结果的HashSet添加到RootObject列表,但你可以添加,如果两者都是类型结果 –

回答

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); 
+0

我需要将此添加到列表键入RootObject ... –

+0

温我用你的代码我没有得到任何错误,但绑定到列表我没有得到values.Thanks你的帮助! –

+0

ListBox2.ItemsSource = sampleRootObject.result;现在我得到列表框中的值..在我使用ListBox2.ItemsSource = approvedList之前.. @philip ngan再次感谢! –

相关问题