public static CompactList ParseJson(JToken list) { CompactList l = new CompactList(); l.Id = Json.TryGetJsonProperty(list, "id"); l.Name = Json.TryGetJsonProperty(list, "name"); l.Description = Json.TryGetJsonProperty(list, "description"); Uri uri = null; Uri.TryCreate(string.Format( CultureInfo.InvariantCulture, "/JeffWilcox.FourthAndMayor.Lists;component/ListView.xaml?id={0}&name={1}&description={2}", l.Id, l.Name, l.Description), UriKind.Relative, out uri); l.LocalListUri = uri; var cu = list["user"]; if (cu != null) { var ocu = CompactUser.ParseJson(cu); if (ocu != null) { l.User = ocu; } } l.IsFollowing = Json.TryGetJsonBool(list, "following"); // TODO: v4: "followers" l.IsEditable = Json.TryGetJsonBool(list, "editable"); l.IsCollaborative = Json.TryGetJsonBool(list, "collaborative"); // TODO: v4: "collaborators" l.CaonicalUri = Json.TryGetUriProperty(list, "caonicalUrl"); var pic = list["photo"]; if (pic != null) { var opic = Photo.ParseJson(pic); if (opic != null) { l.Photo = opic; } } string s = Json.TryGetJsonProperty(list, "doneCount"); int i; if (int.TryParse(s, out i)) { l.DoneCount = i; } s = Json.TryGetJsonProperty(list, "venueCount"); if (int.TryParse(s, out i)) { l.VenueCount = i; } s = Json.TryGetJsonProperty(list, "visitedCount"); if (int.TryParse(s, out i)) { l.VisitedCount = i; } //var b = new List<CompactListItem>(); //var lis = list["listItems"]; //if (lis != null) //{ // var items = lis["items"]; // if (items != null) // { // foreach (var entry in items) // { // var u = CompactListItem.ParseJson(entry); // if (u != null) // { // b.Add(u); // } // } // } //} // l.ListItems = b; return(l); }
public static CompactList ParseJson(JToken list) { CompactList l = new CompactList(); l.Id = Json.TryGetJsonProperty(list, "id"); l.Name = Json.TryGetJsonProperty(list, "name"); l.Description = Json.TryGetJsonProperty(list, "description"); Uri uri = null; Uri.TryCreate(string.Format( CultureInfo.InvariantCulture, "/JeffWilcox.FourthAndMayor.Lists;component/ListView.xaml?id={0}&name={1}&description={2}", l.Id, l.Name, l.Description), UriKind.Relative, out uri); l.LocalListUri = uri; var cu = list["user"]; if (cu != null) { var ocu = CompactUser.ParseJson(cu); if (ocu != null) { l.User = ocu; } } l.IsFollowing = Json.TryGetJsonBool(list, "following"); // TODO: v4: "followers" l.IsEditable = Json.TryGetJsonBool(list, "editable"); l.IsCollaborative = Json.TryGetJsonBool(list, "collaborative"); // TODO: v4: "collaborators" l.CaonicalUri = Json.TryGetUriProperty(list, "caonicalUrl"); var pic = list["photo"]; if (pic != null) { var opic = Photo.ParseJson(pic); if (opic != null) { l.Photo = opic; } } string s = Json.TryGetJsonProperty(list, "doneCount"); int i; if (int.TryParse(s, out i)) { l.DoneCount = i; } s = Json.TryGetJsonProperty(list, "venueCount"); if (int.TryParse(s, out i)) { l.VenueCount = i; } s = Json.TryGetJsonProperty(list, "visitedCount"); if (int.TryParse(s, out i)) { l.VisitedCount = i; } //var b = new List<CompactListItem>(); //var lis = list["listItems"]; //if (lis != null) //{ // var items = lis["items"]; // if (items != null) // { // foreach (var entry in items) // { // var u = CompactListItem.ParseJson(entry); // if (u != null) // { // b.Add(u); // } // } // } //} // l.ListItems = b; return l; }
internal static List <ListsList> ParseListGroups(JToken groups) { List <ListsList> ggg = new List <ListsList>(); if (groups != null) { ListsList lastToAdd = null; foreach (var group in groups) { string type = Json.TryGetJsonProperty(group, "type"); var items = group["items"]; if (items != null) { var ni = new ListsList(); ni.Type = type; string name = Json.TryGetJsonProperty(group, "name"); if (!string.IsNullOrEmpty(name)) { ni.Name = name; } else { if (ni.Type == "todos") { ni.Name = "My To-dos"; } else { // can't be null... ni.Name = string.Empty; // !!! could be a bug farm. // warning, for 'My To-Do List' this is null! ni.Name = "My Lists"; lastToAdd = ni; } } foreach (var item in items) { var list = CompactList.ParseJson(item); if (list != null) { ni.Add(list); } } // This does mean that if there are more // than 1 list that has a null or empty // title, it will get hidden. if (lastToAdd != ni) { ggg.Add(ni); } } } if (lastToAdd != null) { ggg.Add(lastToAdd); lastToAdd = null; } } return(ggg); }