/// <summary> /// JSON帮助类 /// </summary> public static class JsonHelper { /// <summary> /// 格式化成Json字符串 /// </summary> /// <param name="obj">需要格式化的对象</param> /// <returns>Json字符串</returns> public static string ToJson(object obj) { JavaScriptSerializer serializer = new JavaScriptSerializer(); return serializer.Serialize(obj); } /// <summary> /// 格式化成Json字符串 /// </summary> /// <param name="obj">需要格式化的对象</param> /// <param name="recursionDepth">指定序列化的深度</param> /// <returns>Json字符串</returns> public static string ToJson(object obj, int recursionDepth) { JavaScriptSerializer serializer = new JavaScriptSerializer(); serializer.RecursionLimit = recursionDepth; return serializer.Serialize(obj); } }