json文件下载和阅读windows phone 8

时间:2013-06-29 10:12:40

标签: c# windows-phone-7 windows-phone-8-sdk

嗨,我是Windows手机开发的新手,目前我正在开发在线应用程序但是。我有一个问题,如何从网址下载json文件并将其作为文本文件存储到本地存储中,并再次如何阅读文本从它来执行解析。

使用(IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())             {                 如果(isf.FileExists( “file.txt的”))                 {                     using(IsolatedStorageFileStream rawstream = isf.OpenFile(“file.txt”,System.IO.FileMode.Open))                     {                         StreamReader read = new StreamReader(rawstream);                         result = read.ReadLine();                         read.Close();                     }                 }             }             MessageBox.Show(“已完成并已加重”+结果);             }

1 个答案:

答案 0 :(得分:0)

你想要做的是下载一个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"];
}

我发现这篇文章非常有帮助。你应该花一个小时来完成这个样本,让你的生活更轻松。

http://www.developer.nokia.com/Community/Wiki/Picasa_Image_Gallery_with_JSON_in_WP7