2013-06-29 88 views
0

嗨,我是新的Windows手機開發目前我正在在線應用but.i有一個問題,如何從一個URL下載一個JSON文件並將其存儲到本地存儲爲文本文件以及如何從中讀取文本以執行解析。JSON文件下載和閱讀Windows手機8

使用(IsolatedStorageFile ISF = IsolatedStorageFile.GetUserStoreForApplication()){ 如果 (isf.FileExists( 「file.txt的」)) { 使用(IsolatedStorageFileStream rawstream = isf.OpenFile( 「file.txt的」,系統.IO.FileMode.Open)) { StreamReader read = new StreamReader(rawstream); result = read.ReadLine(); read.Close(); } } } MessageBox.Show(「completed and readed」+ result); }

回答

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