.net core 中对象转json以及反序列化

先安装 Newtonsoft.Json 包

public class JsonHelper
    {
        /// 
        /// 将实体类序列化为JSON
        /// 
        /// 
        /// 
        /// 
        public static string SerializeJson(T data)
        {
            return JsonConvert.SerializeObject(data);
        }

        /// 
        /// 反序列化json
        /// 
        /// 
        /// 
        /// 
        public static T DeserializeJson(string json)
        {
            return Newtonsoft.Json.JsonConvert.DeserializeObject(json);
        }

        /// 
        /// 
        /// 
        /// 
        /// 
        public static long ConvertToTimeStamp(DateTime time)
        {
            DateTime dateTime = new DateTime(1993, 1, 2, 3, 4, 5, DateTimeKind.Utc);
            return (long)(time.AddHours(-8) - dateTime).TotalMilliseconds;
        }
    }

 

你可能感兴趣的:(.net core 中对象转json以及反序列化)