Windows Phone 访问Json接口数据并解析成实体

network | | 访问(60)
public partial class MainPage: PhoneApplicationPage {

    // 构造函数
    public MainPage() {
        WebClient webClient = new WebClient();
        webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(ReadCallback_DownloadStringCompleted);
        url = "http://ject.club/api/test";
        webClient.DownloadStringAsync(new Uri(url));

    }
}

/// <summary>
///  回调方法
/// </summary>
private async void ReadCallback_DownloadStringCompleted(Object sender, DownloadStringCompletedEventArgs e) {
    try {
        string result = e.Result;
        MemoryStream mStream = new MemoryStream(Encoding.UTF8.GetBytes(result));
        DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(List<RegionInfo>));
        List<RegionInfo> jsonResult = (List<RegionInfo>) serializer.ReadObject(mStream);
    } catch(Exception ex) {
        Deployment.Current.Dispatcher.BeginInvoke(() = >{
            MessageBox.Show("Network error occured " + ex.Message);
        });
    }
}

/// <summary>
///  省市区实体对象
/// </summary>
public class RegionInfo {

    public int ID {get;set;}

    public int CodeID {get;set;}

    public int ParentID {get;set;}

    public string Name {get;set;}
}