WP8.1開發筆記一:JSON資料處理

來源:互聯網
上載者:User

標籤:des   style   blog   http   io   ar   color   os   sp   

一:建立一個普通的WP8.1應用

二:在解決方案選中項目,右擊 “添加NuGet應用”,添加 json.net

三:把抓包的JSON地址,處理一下

      JSON格式線上校對:http://www.bejson.com/go.html?u=http://www.bejson.com/jsonviewernew/

      JSON產生C#類:http://tools.wx6.org/json2csharp/

四:輸入相關的代碼並且和前台頁面綁定在一塊:

      後台頁面的代碼:

   

using System;using System.Collections.Generic;using System.Linq;using System.Net;using System.Windows;using System.Windows.Controls;using System.Windows.Navigation;using Microsoft.Phone.Controls;using Microsoft.Phone.Shell;using PhoneApp1.Resources;using Newtonsoft.Json;namespace PhoneApp1{    public partial class MainPage : PhoneApplicationPage    {        // 建構函式        public MainPage()        {            InitializeComponent();            this.Loaded += MainPage_Loaded;            // 用於本地化 ApplicationBar 的範例程式碼            //BuildLocalizedApplicationBar();        }        void MainPage_Loaded(object sender, RoutedEventArgs e)        {            WebClient webClient = new WebClient();            webClient.DownloadStringAsync(new Uri("http://wireless.tianya.cn/v/focusStand/rank?type=1&pageSize=100", UriKind.Absolute));            webClient.DownloadStringCompleted += webClient_DownloadStringCompleted;        }        void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)        {            var root = JsonConvert.DeserializeObject<Root>(e.Result);            lls.ItemsSource = root.Data.List;        }        private void lls_SelectionChanged(object sender, SelectionChangedEventArgs e)        {            if (lls.SelectedItem != null)            {                var list = (lls.SelectedItem as List);                MessageBox.Show(list.CategoryId);            }        }     }}

 

前台頁面的代碼:

        <!--ContentPanel - 在此處放置其他內容-->        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">            <phone:LongListSelector x:Name="lls" SelectionChanged="lls_SelectionChanged">                <phone:LongListSelector.ItemTemplate>                    <DataTemplate>                        <StackPanel>                            <TextBlock Text="{Binding CategoryName}"></TextBlock>                        </StackPanel>                    </DataTemplate>                </phone:LongListSelector.ItemTemplate>            </phone:LongListSelector>        </Grid>

完成。

源碼:http://pan.baidu.com/s/1qWM8FRQ

WP8.1開發筆記一:JSON資料處理

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.