public Card(JSONClass json) { if (json == null) { throw new ArgumentNullException("json"); } JsonString = json.ToString(); if (json["id"] == null || json["type"] == null || json["viewed"] == null || json["created"] == null || json["updated"] == null) { throw new ArgumentException("Missing required field(s)."); } ID = json["id"]; Type = json["type"]; Viewed = json["viewed"].AsBool; Created = json["created"].AsInt; Updated = json["updated"].AsInt; Categories = new HashSet<CardCategory>(); if (json["categories"] == null) { Categories.Add(CardCategory.NO_CATEGORY); } else { JSONArray jsonArray = (JSONArray)JSON.Parse(json["categories"].ToString()); if (jsonArray == null || jsonArray.Count == 0) { Categories.Add(CardCategory.NO_CATEGORY); } else { for (int i = 0; i < jsonArray.Count; i++) { CardCategory category = (CardCategory)EnumUtils.TryParse(typeof(CardCategory), jsonArray[i], true, null); if (category != null) { Categories.Add(category); } } } } }
public InAppMessageImmersiveBase(JSONClass json) : base(json) { Header = json[InAppMessageConstants.HeaderKey]; HeaderTextColor = ColorUtils.HexToColor(json[InAppMessageConstants.HeaderTextColorKey]); CloseButtonColor = ColorUtils.HexToColor(json[InAppMessageConstants.CloseButtonColorKey]); if (json[InAppMessageConstants.ButtonsKey] != null) { Buttons = new List<InAppMessageButton>(); JSONArray jsonArray = (JSONArray)JSON.Parse(json[InAppMessageConstants.ButtonsKey].ToString()); Debug.Log(String.Format("parse in-app message with {0} buttons", jsonArray.Count)); for (int i = 0; i < jsonArray.Count; i++) { JSONClass buttonJson = jsonArray[i].AsObject; try { Debug.Log(String.Format("Button no. {0} json string is {1}", i, buttonJson)); InAppMessageButton button = new InAppMessageButton(buttonJson); if (button != null) { Buttons.Add(button); } } catch { Debug.Log(String.Format("Unable to parse button from {0}", buttonJson)); } } } }
public InAppMessageSlideup(JSONClass json) : base(json) { SlideupAnchor = (SlideFrom)EnumUtils.TryParse(typeof(SlideFrom), json[InAppMessageConstants.SlideFromKey], true, SlideFrom.BOTTOM); ChevronColor = ColorUtils.HexToColor(json[InAppMessageConstants.CloseButtonColorKey]); HideChevron = json[InAppMessageConstants.HideChevronKey].AsBool; }
public CrossPromotionSmallCard(JSONClass json) : base(json) { if (json["title"] == null || json["subtitle"] == null || json["caption"] == null || json["rating"] == null || json["reviews"] == null || json["price"] == null || json["url"] == null) { throw new ArgumentException("Missing required field(s)."); } Title = json["title"]; Subtitle = json["subtitle"]; Caption = json["caption"]; ImageUrl = json["image"]; Rating = json["rating"].AsDouble; ReviewCount = json["reviews"].AsInt; Price = json["price"].AsDouble; Url = json["url"]; #if UNITY_ANDROID if (json["package"] == null) { throw new ArgumentException("Missing required field(s)."); } Package = json["package"]; #endif #if UNITY_IOS if (json["media_type"] == null || json["itunes_id"] == null) { throw new ArgumentException("Missing required field(s)."); } MediaType = json["media_type"]; ITunesId = json["itunes_id"].AsInt; if (json["universal"].AsBool) { Universal = json["universal"].AsBool; } #endif }
public ApplePushNotificationAlert(JSONClass json) { LocationArguments = new List<string>(); foreach (var jsonNode in json["loc-args"].AsArray) { LocationArguments.Add(jsonNode.ToString()); } Body = json["body"]; ActionLocationKey = json["action-loc-key"]; LocationKey = json["loc-key"]; LaunchImage = json["launch-image"]; }
/// <summary> /// Converts a JSONClass to a Dictionary of strings. /// </summary> public static Dictionary<string, string> JSONClassToDictionary(JSONClass json) { Dictionary<string, string> dictionary = new Dictionary<string, string>(); if (json != null) { IEnumerator enumerator = json.GetEnumerator(); while (enumerator.MoveNext()) { KeyValuePair<string, JSONNode> entry = (KeyValuePair<string, JSONNode>)enumerator.Current; dictionary.Add(entry.Key, entry.Value); } } return dictionary; }
public InAppMessageButton(JSONClass json) { ButtonID = json[InAppMessageConstants.ButtonIDKey].AsInt; Text = json[InAppMessageConstants.ButtonTextKey]; TextColor = ColorUtils.HexToColor(json[InAppMessageConstants.ButtonTextColorKey]); BackgroundColor = ColorUtils.HexToColor(json[InAppMessageConstants.ButtonBackgroundColorKey]); URI = json[InAppMessageConstants.ButtonURIKey]; ButtonClickAction = (ClickAction)EnumUtils.TryParse(typeof(ClickAction), json[InAppMessageConstants.ButtonClickActionKey], true, ClickAction.NEWS_FEED); if (ButtonClickAction == ClickAction.URI && URI == null) { Debug.Log("The click action cannot be set to URI because the uri is null. Setting click action to NONE."); ButtonClickAction = ClickAction.NONE; } }
public BannerCard(JSONClass json) : base(json) { if (json["image"] == null) { throw new ArgumentException("Missing required field(s)."); } ImageUrl = json["image"]; if (json["url"] != null) { Url = json["url"]; } if (json["domain"] != null) { Domain = json["domain"]; } }
public TextAnnouncementCard(JSONClass json) : base(json) { if (json["title"] == null || json["description"] == null) { throw new ArgumentException("Missing required field(s)."); } Title = json["title"]; Description = json["description"]; if (json["url"] != null) { Url = json["url"]; } if (json["domain"] != null) { Domain = json["domain"]; } }
public CaptionedImageCard(JSONClass json) : base(json) { if (json["image"] == null || json["title"] == null || json["description"] == null) { throw new ArgumentException("Missing required field(s)."); } ImageUrl = json["image"]; Title = json["title"]; Description = json["description"]; if (json["url"] != null) { Url = json["url"]; } if (json["domain"] != null) { Domain = json["domain"]; } }
public ApplePushNotification(JSONClass json) { Alert = new ApplePushNotificationAlert(json["alert"].AsObject); Badge = json["badge"].AsInt; Sound = json["sound"]; ContentAvailable = json["content-available"].AsInt; Extra = new Dictionary<string, object>(); JSONNode ExtraNode = json["extra"]; if (ExtraNode.GetType() == typeof(JSONClass)) { foreach (KeyValuePair<string, JSONNode> KeyValuePairNode in ExtraNode.AsObject) { Extra.Add(KeyValuePairNode.Key, this.getJSONNodeValue(KeyValuePairNode.Value)); } } else { Debug.Log("Value of key Extra isn't a dictionary. Stop parsing the Extra dictionary"); } }
private static Card CreateCardFromJson(JSONClass json) { string type = json["type"]; switch (type) { case "banner_image": return new BannerCard(json); case "captioned_image": return new CaptionedImageCard(json); case "cross_promotion_small": return new CrossPromotionSmallCard(json); case "short_news": return new ClassicCard(json); case "text_announcement": return new TextAnnouncementCard(json); default: return null; } }
public InAppMessageModal(JSONClass json) : base(json) { }
public InAppMessageFull(JSONClass json) : base(json) { }
public static JSONNode Deserialize(System.IO.BinaryReader aReader) { JSONBinaryTag type = (JSONBinaryTag)aReader.ReadByte(); switch(type) { case JSONBinaryTag.Array: { int count = aReader.ReadInt32(); JSONArray tmp = new JSONArray(); for(int i = 0; i < count; i++) tmp.Add(Deserialize(aReader)); return tmp; } case JSONBinaryTag.Class: { int count = aReader.ReadInt32(); JSONClass tmp = new JSONClass(); for(int i = 0; i < count; i++) { string key = aReader.ReadString(); var val = Deserialize(aReader); tmp.Add(key, val); } return tmp; } case JSONBinaryTag.Value: { return new JSONData(aReader.ReadString()); } case JSONBinaryTag.IntValue: { return new JSONData(aReader.ReadInt32()); } case JSONBinaryTag.DoubleValue: { return new JSONData(aReader.ReadDouble()); } case JSONBinaryTag.BoolValue: { return new JSONData(aReader.ReadBoolean()); } case JSONBinaryTag.FloatValue: { return new JSONData(aReader.ReadSingle()); } default: { throw new Exception("Error deserializing JSON. Unknown tag: " + type); } } }
public override void Add(string aKey, JSONNode aItem) { var tmp = new JSONClass(); tmp.Add(aKey, aItem); Set(tmp); }
public override JSONNode this[string aKey] { get { return new JSONLazyCreator(this, aKey); } set { var tmp = new JSONClass(); tmp.Add(aKey, value); Set(tmp); } }