/// <summary> /// petfinder api call to render pet list /// </summary> /// <param name="location"></param> /// <returns></returns> public async Task <List <Pet> > GetPetListJSON(string location) { if (location != null) { string url = "http://api.petfinder.com/pet.find?key=26d124a65947581b27aa9500628f49ef&location=" + location + "&format=json"; using (var httpClient = new HttpClient()) { var jsonstatus = await httpClient.GetAsync(url); if (!jsonstatus.IsSuccessStatusCode) { return(new List <Pet>()); } var json = await httpClient.GetStringAsync(url); PetJSON retrieveJSON = JsonConvert.DeserializeObject <PetJSON>(json); // Now parse with JSON.Net if (retrieveJSON.petfinder.pets == null) { return(new List <Pet>()); } return(retrieveJSON.petfinder.pets.pet.ToList()); } } return(new List <Pet>()); }
public void PetJSONGetSetTest() { PetJSON Pet = new PetJSON(); Pet.petfinder = new Petfinder(); Pet.petfinder.pet = new Pet(); Pet.petfinder.pet.name = new Name(); Pet.petfinder.pet.name.data = "This is a note."; Assert.Equal("This is a note.", Pet.petfinder.pet.name.data); }