public static ComicVineVolume GetVolume(string xmlString) { ComicVineVolume comicVineVolume = new ComicVineVolume(); XDocument xDocument = XDocument.Parse(xmlString); comicVineVolume.url = XmlUtilFunctions.getNodeValue(xDocument, "api_detail_url"); comicVineVolume.count_of_issues = StringUtilFunctions.TryToParse(XmlUtilFunctions.getNodeValue(xDocument, "count_of_issues")); comicVineVolume.volume_description = XmlUtilFunctions.getNodeValue(xDocument, "description"); comicVineVolume.id = StringUtilFunctions.TryToParse(XmlUtilFunctions.getNodeValue(xDocument, "id")); ComicVineImages comicVineImages = new ComicVineImages(); var images = from imgs in xDocument.Descendants("image") select imgs; if (images.Count() > 0) { try { comicVineImages.icon_url = images.Descendants("icon_url").First().Value; comicVineImages.medium_url = images.Descendants("medium_url").First().Value; comicVineImages.screen_url = images.Descendants("screen_url").First().Value; comicVineImages.small_url = images.Descendants("small_url").First().Value; comicVineImages.super_url = images.Descendants("super_url").First().Value; comicVineImages.thumb_url = images.Descendants("thumb_url").First().Value; comicVineImages.tiny_url = images.Descendants("tiny_url").First().Value; } catch (Exception ex) { } } comicVineVolume.images = comicVineImages; List <ComicVineIssue> comicVineIssueList = new List <ComicVineIssue>(); var issues = from iss in xDocument.Descendants("issue") select iss; foreach (var issue in issues) { ComicVineIssue comicVineIssue = new ComicVineIssue(); comicVineIssue.id = StringUtilFunctions.TryToParse(issue.Descendants("id").First().Value); comicVineIssue.api_detail_url = issue.Descendants("api_detail_url").First().Value; comicVineIssue.name = issue.Descendants("name").First().Value; comicVineIssue.issue_number = issue.Descendants("issue_number").First().Value; comicVineIssueList.Add(comicVineIssue); } comicVineVolume.list_of_issue = comicVineIssueList; comicVineVolume.name = XmlUtilFunctions.getNodeValue(xDocument, "name"); ComicVinePublisher comicVinePublisher = new ComicVinePublisher(); var publishers = from publ in xDocument.Descendants("publisher") select publ; if (publishers != null & publishers.Count() > 0) { try { comicVinePublisher.publisher_name = publishers.Descendants("name").First().Value; comicVinePublisher.publisher_id = StringUtilFunctions.TryToParse(publishers.Descendants("id").First().Value); comicVinePublisher.publisher_url = publishers.Descendants("api_detail_url").First().Value; } catch (Exception ex) { } } comicVineVolume.publisher = comicVinePublisher; comicVineVolume.start_year = StringUtilFunctions.TryToParse(XmlUtilFunctions.getNodeValue(xDocument, "start_year")); return(comicVineVolume); }
public static ComicVineVolume GetVolume(string jsonData) { ComicVineVolume detailedComicVineVolume = new ComicVineVolume(); JObject jObject = JObject.Parse(jsonData); var results = jObject["results"]["publisher"]; detailedComicVineVolume.url = jObject["results"]["api_detail_url"].ToString(); string countOfIssues = jObject["results"]["count_of_issues"].ToString(); detailedComicVineVolume.count_of_issues = StringUtilFunctions.TryToParse(countOfIssues); detailedComicVineVolume.volume_description = jObject["results"]["description"].ToString(); string volumeId = jObject["results"]["id"].ToString(); detailedComicVineVolume.id = StringUtilFunctions.TryToParse(volumeId); detailedComicVineVolume.name = jObject["results"]["name"].ToString();; string startYear = jObject["results"]["start_year"].ToString(); detailedComicVineVolume.start_year = StringUtilFunctions.TryToParse(startYear); // Get the volume images //var timages = from imgs in xdoc.Descendants("image") select imgs; ComicVineImages images = new ComicVineImages(); if (!String.IsNullOrEmpty(jObject["results"]["image"].ToString())) { try { images = JsonConvert.DeserializeObject <ComicVineImages>(jObject["results"]["image"].ToString()); } catch (Exception ex) { // We don't catch this exeption. } } detailedComicVineVolume.images = images; // Get the collection of issues //List<ComicVineIssue> comicVineIssueList = new List<ComicVineIssue>(); //IList<JToken> jIssues = jObject["results"]["issues"].Children().ToList(); //foreach (JToken issues in jIssues) //{ // ComicVineIssue comicVineIssue = JsonConvert.DeserializeObject<ComicVineIssue>(issues.ToString()); // comicVineIssueList.Add(comicVineIssue); //} //detailedComicVineVolume.list_of_issue = comicVineIssueList; ComicVinePublisher publisher = new ComicVinePublisher(); publisher = JsonConvert.DeserializeObject <ComicVinePublisher>(jObject["results"]["publisher"].ToString()); detailedComicVineVolume.publisher = publisher; return(detailedComicVineVolume); }