C# 使用Webservice的响应创建xaml列表

C# 使用Webservice的响应创建xaml列表,c#,xaml,windows-phone-8,C#,Xaml,Windows Phone 8,我正在尝试使用从Web服务(成功)收到的响应,并使用该响应在xaml端“创建”或“填充”列表 这里是json { "success":true, "code":200, "rows":[ { "Purchase":{ "id":"1" }, "Who":{ "id":"1", "value":"NA" }

我正在尝试使用从Web服务(成功)收到的响应,并使用该响应在xaml端“创建”或“填充”列表

这里是json

{  
   "success":true,
   "code":200,
   "rows":[  
      {  
         "Purchase":{  
            "id":"1"
         },
         "Who":{  
            "id":"1",
            "value":"NA"
         },
         "What":{  
            "id":"1",
            "value":"what-text"
         }
      },
      {  
         "Purchase":{  
            "id":"2"
         },
         "Who":{  
            "id":"2",
            "value":"ME"
         },
         "What":{  
            "id":"1",
            "value":"what-text"
         }
      }
   ]
}
我从我的CS那里得到了这样的Web服务

HttpWebRequest hwr = rez.AsyncState as HttpWebRequest;
HttpWebResponse response = hwr.EndGetResponse(rez) as HttpWebResponse;
string jsonResponseString = (new StreamReader(response.GetResponseStream(), Encoding.UTF8)).ReadToEnd();

Dispatcher.BeginInvoke(() =>
{
    var responseObject =
        Newtonsoft.Json.JsonConvert.DeserializeObject(jsonResponseString);
});
这很有效。“jsonResponseString”返回了上面显示的json

现在我想在我的xaml页面上显示这些结果。在这里我已经有了一个问题,什么是最好的使用。。一个长列表选择器?还是一张桌子可以用

在我的CS中,我还设置了:

public class Purchase
{
    public List<string> Who { get; set; }
    public List<string> What { get; set; }
}

public class RootObject
{
    public List<Purchase> purchase { get; set; }
    public int success { get; set; }
    public string message { get; set; }
} 
公共类购买
{
公共列表{get;set;}
公共列表内容{get;set;}
}
公共类根对象
{
公共列表购买{get;set;}
公共int成功{get;set;}
公共字符串消息{get;set;}
} 
我找到了可以用的地方,但可能不需要

无论如何,我想弄清楚在xaml视图中最好使用什么,以及如何使用json返回的字符串或对象将数据填充到该视图中


谢谢

您的类应该这样设置以匹配JSON结构:

public class Item
{ 
    public int id { get; set; }
    public string value { get; set; }
}

public class Row
{
    public Item Purchase { get; set; }
    public Item Who { get; set; }
    public Item What { get; set; }
}

public class RootObject
{
    public List<Row> rows { get; set; }
    public bool success { get; set; }
    public int code { get; set; }
} 

一个主细节视图可能会有所帮助:感谢您的回复和解释,我会继续努力,让您知道会发生什么。再次感谢!工作得很有魅力!谢谢McGarnagle先生!
RootObject responseObject = Newtonsoft.Json.JsonConvert.DeserializeObject<RootObject>(jsonResponseString);
<ListBox>
    <ListBox.ItemTemplate>
        <DataTemplate>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <TextBlock Grid.Column="0" Text="{Binding Who.value}" />
                <TextBlock Grid.Column="1" Text="{Binding What.value}" />
            </Grid>
        </DataTemplate>
    </ListBox.ItemTemplate>
    <ListBox.ItemContainerStyle>
        <Style TargetType="ListBoxItem">
            <Setter Property="HorizontalAlignment" Value="Stretch" />
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        </Style>
    </ListBox.ItemContainerStyle>
</ListBox>