1
   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; }

        }

This is My C# code. I am able to count the Number of items var rootObject = JsonConvert.DeserializeObject<List<Contacts>>(e.Result); contain in response But i am Unable to Print data. Please help me how I can print. Please print atleast One item so that i can Understand

4

1 回答 1

0

您必须在 XAML 中准备 UI 并从代码隐藏设置数据绑定。

示例 xml 代码:

<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>

以及来自代码隐藏的数据绑定。

void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
    {
        var rootObject = JsonConvert.DeserializeObject<List<Contacts>>(e.Result);
        ListBoxNews.ItemsSource = rootObject;
    }

试试这个,问我你是否还有疑问。

于 2013-03-19T11:48:10.690 回答