private async Task GetSampleDataAsync() { if (this._groups.Count != 0) return; // Uri dataUri = new Uri("ms-appx:///DataModel/SampleData.json"); // StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(dataUri); //string jsonText = await FileIO.ReadTextAsync(file); try { Windows.Web.Http.HttpClient client = new Windows.Web.Http.HttpClient(); var jsonText = await client.GetStringAsync(new Uri("http://bits-oasis.org/2015/windows_json/")); JsonObject jsonObject = JsonObject.Parse(jsonText); JsonArray jsonArray = jsonObject["Groups"].GetArray(); foreach (JsonValue groupValue in jsonArray) { JsonObject groupObject = groupValue.GetObject(); SampleDataGroup group = new SampleDataGroup(groupObject["UniqueId"].GetString(), groupObject["Title"].GetString() //groupObject["Subtitle"].GetString(), // groupObject["ImagePath"].GetString(), // groupObject["Description"].GetString() ); int i = 0; foreach (JsonValue itemValue in groupObject["Items"].GetArray()) { JsonObject itemObject = itemValue.GetObject(); group.Items.Add(new SampleDataItem(itemObject["UniqueId"].GetString(), itemObject["Title"].GetString(), itemObject["Subtitle"].GetString(), itemObject["ImagePath"].GetString(), // itemObject["Description"].GetString(), itemObject["Content"].GetString())); foreach (JsonValue subitemValue in itemObject["SubItems"].GetArray()) { JsonObject subitemObject = subitemValue.GetObject(); group.Items[i].SubItems.Add(new SampleDataSubItem(subitemObject["UniqueId"].GetString(), subitemObject["Title"].GetString(), subitemObject["Subtitle"].GetString(), subitemObject["ImagePath"].GetString(), // itemObject["Description"].GetString(), subitemObject["Content"].GetString())); } i++; } this.Groups.Add(group); } } catch { MessageDialog msgbox3 = new MessageDialog("Check Your Network Connection. Web Access is required to get data."); await msgbox3.ShowAsync(); } }
private async Task GetSampleDataAsync() { if (this._groups.Count != 0) return; Uri dataUri = new Uri("ms-appx:///DataModel/SampleData.json"); StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(dataUri); string jsonText = await FileIO.ReadTextAsync(file); JsonObject jsonObject = JsonObject.Parse(jsonText); JsonArray jsonArray = jsonObject["Groups"].GetArray(); foreach (JsonValue groupValue in jsonArray) { JsonObject groupObject = groupValue.GetObject(); SampleDataGroup group = new SampleDataGroup(groupObject["UniqueId"].GetString(), groupObject["Title"].GetString() //groupObject["Subtitle"].GetString(), // groupObject["ImagePath"].GetString(), // groupObject["Description"].GetString() ); int i = 0; foreach (JsonValue itemValue in groupObject["Items"].GetArray()) { JsonObject itemObject = itemValue.GetObject(); group.Items.Add(new SampleDataItem(itemObject["UniqueId"].GetString(), itemObject["Title"].GetString(), itemObject["Subtitle"].GetString(), itemObject["ImagePath"].GetString(), // itemObject["Description"].GetString(), itemObject["Content"].GetString())); foreach (JsonValue subitemValue in itemObject["SubItems"].GetArray()) { JsonObject subitemObject = subitemValue.GetObject(); group.Items[i].SubItems.Add(new SampleDataSubItem(subitemObject["UniqueId"].GetString(), subitemObject["Title"].GetString(), subitemObject["Subtitle"].GetString(), subitemObject["ImagePath"].GetString(), // itemObject["Description"].GetString(), subitemObject["Content"].GetString())); } i++; } this.Groups.Add(group); } }