public static SwrveMessageFormat LoadFromJSON(ISwrveAssetsManager swrveAssetsManager, SwrveMessage message, Dictionary <string, object> messageFormatData, Color?defaultBackgroundColor)
        {
            SwrveMessageFormat swrveMessageFormat = new SwrveMessageFormat(message);

            swrveMessageFormat.Name     = (string)messageFormatData["name"];
            swrveMessageFormat.Language = (string)messageFormatData["language"];
            if (messageFormatData.ContainsKey("scale"))
            {
                swrveMessageFormat.Scale = MiniJsonHelper.GetFloat(messageFormatData, "scale", 1f);
            }
            if (messageFormatData.ContainsKey("orientation"))
            {
                swrveMessageFormat.Orientation = SwrveOrientationHelper.Parse((string)messageFormatData["orientation"]);
            }
            swrveMessageFormat.BackgroundColor = defaultBackgroundColor;
            if (messageFormatData.ContainsKey("color"))
            {
                string text            = (string)messageFormatData["color"];
                Color? backgroundColor = swrveMessageFormat.BackgroundColor;
                if (text.Length == 8)
                {
                    byte a = byte.Parse(text.Substring(0, 2), NumberStyles.HexNumber);
                    byte r = byte.Parse(text.Substring(2, 2), NumberStyles.HexNumber);
                    byte g = byte.Parse(text.Substring(4, 2), NumberStyles.HexNumber);
                    byte b = byte.Parse(text.Substring(6, 2), NumberStyles.HexNumber);
                    backgroundColor = new Color32(r, g, b, a);
                }
                else if (text.Length == 6)
                {
                    byte r = byte.Parse(text.Substring(0, 2), NumberStyles.HexNumber);
                    byte g = byte.Parse(text.Substring(2, 2), NumberStyles.HexNumber);
                    byte b = byte.Parse(text.Substring(4, 2), NumberStyles.HexNumber);
                    backgroundColor = new Color32(r, g, b, byte.MaxValue);
                }
                swrveMessageFormat.BackgroundColor = backgroundColor;
            }
            Dictionary <string, object> dictionary = (Dictionary <string, object>)messageFormatData["size"];

            swrveMessageFormat.Size.X = MiniJsonHelper.GetInt((Dictionary <string, object>)dictionary["w"], "value");
            swrveMessageFormat.Size.Y = MiniJsonHelper.GetInt((Dictionary <string, object>)dictionary["h"], "value");
            IList <object> list = (List <object>)messageFormatData["buttons"];
            int            i    = 0;

            for (int count = list.Count; i < count; i++)
            {
                SwrveButton item = LoadButtonFromJSON(message, (Dictionary <string, object>)list[i]);
                swrveMessageFormat.Buttons.Add(item);
            }
            IList <object> list2 = (List <object>)messageFormatData["images"];
            int            j     = 0;

            for (int count2 = list2.Count; j < count2; j++)
            {
                SwrveImage item2 = LoadImageFromJSON(message, (Dictionary <string, object>)list2[j]);
                swrveMessageFormat.Images.Add(item2);
            }
            return(swrveMessageFormat);
        }
        /// <summary>
        /// Load an in-app message format from a JSON response.
        /// </summary>
        /// <param name="message">
        /// Parent in-app message.
        /// </param>
        /// <param name="messageFormatData">
        /// JSON object with the individual message format data.
        /// </param>
        /// <returns>
        /// Parsed in-app message format.
        /// </returns>
        public static SwrveMessageFormat LoadFromJSON(SwrveSDK sdk, SwrveMessage message, Dictionary <string, object> messageFormatData)
        {
            SwrveMessageFormat messageFormat = new SwrveMessageFormat(message);

            messageFormat.Name     = (string)messageFormatData ["name"];
            messageFormat.Language = (string)messageFormatData ["language"];
            if (messageFormatData.ContainsKey("scale"))
            {
                messageFormat.Scale = MiniJsonHelper.GetFloat(messageFormatData, "scale", 1);
            }

            if (messageFormatData.ContainsKey("orientation"))
            {
                messageFormat.Orientation = SwrveOrientationHelper.Parse((string)messageFormatData ["orientation"]);
            }

            messageFormat.BackgroundColor = sdk.DefaultBackgroundColor;
            if (messageFormatData.ContainsKey("color"))
            {
                string strColor = (string)messageFormatData ["color"];
                Color? c        = messageFormat.BackgroundColor;
                if (strColor.Length == 8)
                {
                    // RRGGBB
                    byte a = byte.Parse(strColor.Substring(0, 2), System.Globalization.NumberStyles.HexNumber);
                    byte r = byte.Parse(strColor.Substring(2, 2), System.Globalization.NumberStyles.HexNumber);
                    byte g = byte.Parse(strColor.Substring(4, 2), System.Globalization.NumberStyles.HexNumber);
                    byte b = byte.Parse(strColor.Substring(6, 2), System.Globalization.NumberStyles.HexNumber);
                    c = new Color32(r, g, b, a);
                }
                else if (strColor.Length == 6)
                {
                    // AARRGGBB
                    byte r = byte.Parse(strColor.Substring(0, 2), System.Globalization.NumberStyles.HexNumber);
                    byte g = byte.Parse(strColor.Substring(2, 2), System.Globalization.NumberStyles.HexNumber);
                    byte b = byte.Parse(strColor.Substring(4, 2), System.Globalization.NumberStyles.HexNumber);
                    c = new Color32(r, g, b, 255);
                }
                messageFormat.BackgroundColor = c;
            }

            Dictionary <string, object> sizeJson = (Dictionary <string, object>)messageFormatData ["size"];

            messageFormat.Size.X = MiniJsonHelper.GetInt(((Dictionary <string, object>)sizeJson ["w"]), "value");
            messageFormat.Size.Y = MiniJsonHelper.GetInt(((Dictionary <string, object>)sizeJson ["h"]), "value");

            IList <object> jsonButtons = (List <object>)messageFormatData ["buttons"];

            for (int i = 0, j = jsonButtons.Count; i < j; i++)
            {
                SwrveButton button = LoadButtonFromJSON(message, (Dictionary <string, object>)jsonButtons [i]);
                messageFormat.Buttons.Add(button);
            }

            IList <object> jsonImages = (List <object>)messageFormatData ["images"];

            for (int ii = 0, ji = jsonImages.Count; ii < ji; ii++)
            {
                SwrveImage image = LoadImageFromJSON(message, (Dictionary <string, object>)jsonImages [ii]);
                messageFormat.Images.Add(image);
            }


            return(messageFormat);
        }