Advertisement
JAcob_007

SpaceViewModel

Feb 10th, 2017
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 KB | None | 0 0
  1. using System.Net.Http;
  2. using Newtonsoft.Json;
  3. using ParseJsonData.Models;
  4. using System.Threading.Tasks;
  5. using System.Collections;
  6. using System.Collections.Generic;
  7.  
  8. namespace ParseJsonData.ViewModels
  9. {
  10.     public class SpaceViewModel
  11.     {
  12.         IEnumerable _posts;
  13.        
  14.         public async Task<IEnumerable<Post>> GetPostsAsync()
  15.         {
  16.             if (this._posts != null)
  17.                 return _posts;
  18.  
  19.             this._posts = new List<Post>();
  20.  
  21.             var client = new HttpClient();
  22.             var myjsondata = await client.GetAsync("http://lyon.us.com/simpledata.json");
  23.             myjsondata.EnsureSuccessStatusCode();
  24.  
  25.             var spacesJson = await myjsondata.Content.ReadAsStringAsync();
  26.             var rootObject = JsonConvert.DeserializeObject<RootObject>(spacesJson);
  27.  
  28.             foreach (var space_json in rootObject.posts)
  29.             {
  30.                 //I want to get the "title";
  31.                 //"value" if the "key" is city and country
  32.                 //and put into ObservableCollections so that can Bind in my Listview
  33.                 //Can someone help me please,
  34.                     this._posts.add(space_json);
  35.             }
  36.  
  37.             return _posts;
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement