private static bool SerializeValue(IJsonSerializerStrategy jsonSerializerStrategy, object value, StringBuilder builder)
        {
            bool   flag = true;
            string text = value as string;

            if (text != null)
            {
                flag = SimpleJsonTool.SerializeString(text, builder);
            }
            else
            {
                IDictionary <object, object> dictionary = value as IDictionary <object, object>;
                if (dictionary != null)
                {
                    flag = SimpleJsonTool.SerializeObject(jsonSerializerStrategy, dictionary.Keys, dictionary.Values, builder);
                }
                else
                {
                    //UnityEngine.Debug.Log("===>>IEnumerable");
                    IEnumerable enumerable = value as IEnumerable;
                    if (enumerable != null)
                    {
                        flag = SimpleJsonTool.SerializeArray(jsonSerializerStrategy, enumerable, builder);
                    }
                    else if (SimpleJsonTool.IsNumeric(value))
                    {
                        flag = SimpleJsonTool.SerializeNumber(value, builder);
                    }
                    else if (value is bool)
                    {
                        builder.Append((!(bool)value) ? "false" : "true");
                    }
                    else if (value == null)
                    {
                        builder.Append("null");
                    }
                    else
                    {
                        object value2;
                        flag = jsonSerializerStrategy.TrySerializeNonPrimitiveObject(value, out value2);
                        if (flag)
                        {
                            SimpleJsonTool.SerializeValue(jsonSerializerStrategy, value2, builder);
                        }
                    }
                }
            }
            return(flag);
        }
 public static string ToJson(object data)
 {
     try
     {
         object temp = ChangeObjectToJsonObject(data);
         if (null == temp)
         {
             return("");
         }
         return(SimpleJsonTool.SerializeObject(temp));
     }
     catch (Exception e)
     {
         Debug.LogError(e);
     }
     return(null);
 }
        /// <summary>
        /// Dictionary<k,v>转换为json
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        private static string DictionaryToJson(object data)
        {
            object obj = DictionaryToJsonObject(data);

            return(SimpleJsonTool.SerializeObject(obj));
        }
        /// <summary>
        /// class或struct转换为json
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        private static string ClassOrStructToJson(object data)
        {
            object jsonObject = ClassOrStructToJsonObject(data);

            return(SimpleJsonTool.SerializeObject(jsonObject));
        }
        /// <summary>
        /// Array转换为Json
        /// </summary>
        /// <param name="datas"></param>
        /// <returns></returns>
        private static string ArrayToJson(object datas)
        {
            object temp = ListArrayToJsonObject(datas, false);

            return(SimpleJsonTool.SerializeObject(temp));
        }
 public static string SerializeObject(object json)
 {
     return(SimpleJsonTool.SerializeObject(json, SimpleJsonTool.CurrentJsonSerializerStrategy));
 }
Example #7
0
 public override string ToString()
 {
     return(SimpleJsonTool.SerializeObject(this) ?? string.Empty);
 }