Windows phone 7 如何使用C代码在Windwos Phone 7中解析和显示Json数据
这是我的C代码。我能够计算var rootObject=JsonConvert.DeserializeObjecte.Result的项目数;包含响应,但我无法打印数据。请帮助我如何打印。请至少打印一个项目,以便我能理解您必须在XAML中准备UI并从codebehind设置数据绑定Windows phone 7 如何使用C代码在Windwos Phone 7中解析和显示Json数据,windows-phone-7,c#-4.0,Windows Phone 7,C# 4.0,这是我的C代码。我能够计算var rootObject=JsonConvert.DeserializeObjecte.Result的项目数;包含响应,但我无法打印数据。请帮助我如何打印。请至少打印一个项目,以便我能理解您必须在XAML中准备UI并从codebehind设置数据绑定 <ListBox Name="ListBoxNews" Margin="10,0,30,0" Height="486" Width="404" FontSize="20"> <
<ListBox Name="ListBoxNews" Margin="10,0,30,0" Height="486" Width="404" FontSize="20">
<ListBox.ItemTemplate>
<DataTemplate >
<StackPanel Margin="10,0,10,8">
<TextBlock Text="{Binding news_date}" TextWrapping="Wrap" FontSize="18" />
<TextBlock Text="{Binding news_title}" TextWrapping="Wrap" FontSize="24" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
xaml代码示例:
void myButton_Click(object sender, RoutedEventArgs e)
{
WebClient webClient = new WebClient();
webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient_DownloadStringCompleted);
webClient.DownloadStringAsync(new Uri("http://www.taxmann.com/TaxmannWhatsnewService/mobileservice.aspx?service=topstories"));
}
void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
var rootObject = JsonConvert.DeserializeObject<List<Contacts>>(e.Result);
}
public class Contacts
{
public string news_id { get; set; }
public string news_title { get; set; }
public string website_link { get; set; }
public string imagepath { get; set; }
public string news_date { get; set; }
public string news_detail_description { get; set; }
}
以及从codebehind进行数据绑定
<ListBox Name="ListBoxNews" Margin="10,0,30,0" Height="486" Width="404" FontSize="20">
<ListBox.ItemTemplate>
<DataTemplate >
<StackPanel Margin="10,0,10,8">
<TextBlock Text="{Binding news_date}" TextWrapping="Wrap" FontSize="18" />
<TextBlock Text="{Binding news_title}" TextWrapping="Wrap" FontSize="24" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
试试这个,如果你还有疑问的话问我。thanx我正在努力,会给你回复的