【问题标题】:json file downloading and reading windows phone 8json文件下载和读取windows phone 8
【发布时间】:2013-06-29 10:12:40
【问题描述】:

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

使用 (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication()) { if(isf.FileExists("file.txt")) { 使用 (IsolatedStorageFileStream rawstream = isf.OpenFile("file.txt", System.IO.FileMode.Open)) { StreamReader 读取 = 新 StreamReader(rawstream); 结果 = read.ReadLine(); 读。关闭(); } } } MessageBox.Show("完成并阅读" + 结果); }

【问题讨论】:

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


    【解决方案1】:

    你要做的是下载一个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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多