C# json文件下载和读取windows phone 8

C# json文件下载和读取windows phone 8,c#,windows-phone-7,windows-phone-8-sdk,C#,Windows Phone 7,Windows Phone 8 Sdk,您好,我是windows phone开发新手,目前我正在开发在线应用程序,但我遇到了一个问题,即如何从url下载json文件并将其作为文本文件存储到本地存储,以及如何从中读取文本以执行解析 使用(IsolatedStorageFile isf=IsolatedStorageFile.GetUserStoreForApplication()) { 如果(isf.FileExists(“file.txt”)) { 使用(IsolatedStorageFileStream rawstream=isf.

您好,我是windows phone开发新手,目前我正在开发在线应用程序,但我遇到了一个问题,即如何从url下载json文件并将其作为文本文件存储到本地存储,以及如何从中读取文本以执行解析

使用(IsolatedStorageFile isf=IsolatedStorageFile.GetUserStoreForApplication()) { 如果(isf.FileExists(“file.txt”)) { 使用(IsolatedStorageFileStream rawstream=isf.OpenFile(“file.txt”,System.IO.FileMode.Open)) { StreamReader read=新的StreamReader(rawstream); 结果=read.ReadLine(); read.Close(); } } } MessageBox.Show(“完成并读取”+结果);
}您要做的是下载一个json,然后解析它

下载json文件

private void GetAlbums()
{
    WebClient webClient = new WebClient();
    Uri uri = new Uri(dataFeed, UriKind.Absolute);
    webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(AlbumsDownloaded);
    webClient.DownloadStringAsync(uri);
}
  public void AlbumsDownloaded(object sender,   DownloadStringCompletedEventArgs e)
  {
        // Deserialize JSON string to dynamic object
        IDictionary<string, object> json = (IDictionary<string, object>)SimpleJson.DeserializeObject(e.Result);
        // Feed object
        IDictionary<string, object> feed = (IDictionary<string, object>)json["feed"];
}
解析和读取此文件

private void GetAlbums()
{
    WebClient webClient = new WebClient();
    Uri uri = new Uri(dataFeed, UriKind.Absolute);
    webClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(AlbumsDownloaded);
    webClient.DownloadStringAsync(uri);
}
  public void AlbumsDownloaded(object sender,   DownloadStringCompletedEventArgs e)
  {
        // Deserialize JSON string to dynamic object
        IDictionary<string, object> json = (IDictionary<string, object>)SimpleJson.DeserializeObject(e.Result);
        // Feed object
        IDictionary<string, object> feed = (IDictionary<string, object>)json["feed"];
}
public void相册下载(对象发送方,下载StringCompletedEventArgs e)
{
//将JSON字符串反序列化为动态对象
IDictionary json=(IDictionary)SimpleJson.DeserializeObject(e.Result);
//馈送对象
IDictionary提要=(IDictionary)json[“提要”];
}
我觉得这篇文章很有帮助。你应该花一个小时来检查这个样本,以使你的生活更轻松