public
Created

Process and display zoo.json

  • Download Gist
processAndDisplayZooJSON.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
args.setPromise(WinJS.UI.processAll().then(function() {
//build up the URL for the file added to the project
var url = new Windows.Foundation.Uri("ms-appx:///zoo.json");
 
//this will store the imported data
var myNewAnimals = new Array();
 
//invoke the static method which loads the file
//and creates Animal objects from json data
//THE METHOD RETURNS A PROMISE!!!
Zoo.Animal.loadZoo(url).done(
 
function (result) {
myNewAnimals = result;
 
myNewAnimals.forEach(function (animal) {
console.log("Name: " + animal.getName() + ", Age: " + animal.getAge() + ", IsHungry: " + animal.isHungry() + ", Hours since Last feed: " + animal.getHoursSinceLastFeed());
});
},
function (error) {
var messDialog = new Windows.UI.Popups.MessageDialog(error);
messDialog.showAsync();
});
 
}));

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.