public void getShowCastPerShow() { var showlist = _showsRepository.FindAllShows(); if (showlist != null) { foreach (var s in showlist) { int id = s.ShowId; var apiRes = jsonString("http://api.tvmaze.com/shows/" + id + "/cast"); JArray jsonResponse = JArray.Parse(apiRes); string myId, myName, myBirthday, mygender; foreach (var item in jsonResponse) { myBirthday = myId = mygender = myName = ""; var cnt = 0; JObject jPerson = (JObject)item["person"]; foreach (var rItem in jPerson) { string rItemKey = rItem.Key; string myVal = rItem.Value.ToString(); switch (rItemKey) { case "name": myName = rItem.Value.ToString(); cnt++; break; case "birthday": myBirthday = rItem.Value.ToString(); cnt++; break; case "id": myId = rItem.Value.ToString(); cnt++; break; } if (cnt == 3) { break; } } //do your save here DateTime?myDate = null; DateTime outDate; if (DateTime.TryParse(myBirthday, out outDate)) { myDate = outDate; } var showsCast = new ShowCast { name = myName, birthday = myDate, Castid = int.Parse(myId), Showsid = id }; _ishowCastRepository.AddShowsCast(showsCast); } } } }