Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Net.Http;
- using Newtonsoft.Json;
- using ParseJsonData.Models;
- using System.Threading.Tasks;
- using System.Collections;
- using System.Collections.Generic;
- namespace ParseJsonData.ViewModels
- {
- public class SpaceViewModel
- {
- IEnumerable _posts;
- public async Task<IEnumerable<Post>> GetPostsAsync()
- {
- if (this._posts != null)
- return _posts;
- this._posts = new List<Post>();
- var client = new HttpClient();
- var myjsondata = await client.GetAsync("http://lyon.us.com/simpledata.json");
- myjsondata.EnsureSuccessStatusCode();
- var spacesJson = await myjsondata.Content.ReadAsStringAsync();
- var rootObject = JsonConvert.DeserializeObject<RootObject>(spacesJson);
- foreach (var space_json in rootObject.posts)
- {
- //I want to get the "title";
- //"value" if the "key" is city and country
- //and put into ObservableCollections so that can Bind in my Listview
- //Can someone help me please,
- this._posts.add(space_json);
- }
- return _posts;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement