public static class JsonFormatter { /// <summary> /// 将对象序列化json /// </summary> /// <typeparam name="T"></typeparam> /// <param name="value"></param> /// <returns></returns> public static string Serialize<T>(T value) { if (value == null) return null; using (var ms = new MemoryStream()) { var ser = new DataContractJsonSerializer(typeof(T)); ser.WriteObject(ms, value); ms.Position = 0; using(var sr = new StreamReader(ms, System.Text.Encoding.UTF8)) { return sr.ReadToEnd(); } } } }