public static VkWallEntry FromJson(JToken json) { if (json == null) { throw new ArgumentException("Json can not be null."); } VkWallEntry vkWallEntry = new VkWallEntry(); vkWallEntry.Id = json["id"].Value <double>(); if (json["attachments"] != null) { vkWallEntry.Attachments = new List <VkAttachment>(); using (IEnumerator <JToken> enumerator = json["attachments"].AsEnumerable().GetEnumerator()) { while (enumerator.MoveNext()) { JToken current = enumerator.Current; string text; if ((text = current["type"].Value <string>()) != null && text == "audio") { vkWallEntry.Attachments.Add(VkAudioAttachment.FromJson(current["audio"])); } } } } return(vkWallEntry); }
public static VkNewsEntry FromJson(JToken json) { if (json == null) { throw new ArgumentException("Json can not be null."); } VkNewsEntry vkNewsEntry = new VkNewsEntry(); if (json["post_id"] != null) { vkNewsEntry.Id = json["post_id"].Value <long>(); } if (json["type"] != null) { vkNewsEntry.Type = json["type"].Value <string>(); } if (json["source_id"] != null) { vkNewsEntry.SourceId = json["source_id"].Value <long>(); } if (json["date"] != null) { vkNewsEntry.Date = DateTimeExtensions.UnixTimeStampToDateTime((double)json["date"].Value <long>()); } if (json["text"] != null) { vkNewsEntry.Text = json["text"].Value <string>(); vkNewsEntry.Text = vkNewsEntry.Text.Replace("<br>", Environment.NewLine); } if (json["attachments"] != null) { vkNewsEntry.Attachments = new List <VkAttachment>(); using (IEnumerator <JToken> enumerator = json["attachments"].AsEnumerable().GetEnumerator()) { while (enumerator.MoveNext()) { JToken current = enumerator.Current; string text; if ((text = current["type"].Value <string>()) != null) { if (!(text == "audio")) { if (text == "photo") { vkNewsEntry.Attachments.Add(VkPhotoAttachment.FromJson(current["photo"])); } } else { vkNewsEntry.Attachments.Add(VkAudioAttachment.FromJson(current["audio"])); } } } } } if (json["comments"] != null) { vkNewsEntry.CommentsCount = json["comments"]["count"].Value <long>(); vkNewsEntry.CanWriteComment = (json["comments"]["can_post"].Value <int>() == 1); } return(vkNewsEntry); }
public static VkWallEntry FromJson(JToken json) { if (json == null) { throw new ArgumentException("Json can not be null."); } var result = new VkWallEntry(); result.Id = json["id"].Value <double>(); if (json["text"] != null) { result.Text = WebUtility.HtmlDecode(json["text"].Value <string>()); result.Text = result.Text.Replace("<br>", Environment.NewLine); } if (json["from_id"] != null) { result.SourceId = json["from_id"].Value <long>(); } if (json["date"] != null) { result.Date = DateTimeExtensions.UnixTimeStampToDateTime(json["date"].Value <long>()); } if (json["attachments"] != null) { result.Attachments = new List <VkAttachment>(); foreach (var a in json["attachments"]) { switch (a["type"].Value <string>()) { case "audio": result.Attachments.Add(VkAudioAttachment.FromJson(a["audio"])); break; case "photo": result.Attachments.Add(VkPhotoAttachment.FromJson(a["photo"])); break; } } } if (json["copy_history"] != null) { result.CopyHistory = new List <VkWallEntry>(); foreach (var p in json["copy_history"]) { try { var post = VkWallEntry.FromJson(p); if (post != null) { result.CopyHistory.Add(post); } } catch (Exception ex) { Debug.WriteLine(ex); } } } return(result); }