c# Newtonsoft.Json封装

2021-07-09 04:09

阅读:596

标签:HERE   string   json   oid   ring   []   serialize   serial   convert   

    public static T Deserialize(string content) where T : class, new()
        {
            return JsonConvert.DeserializeObject(content);
        }

        public static string Serialize(T obj) where T : class, new()
        {
            return JsonConvert.SerializeObject(obj);
        }

        public static void Serialize(T obj, S stream) where S : Stream where T : class, new()
        {
            using (stream)
            {
                byte[] content = System.Text.Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(obj));
                stream.Write(content, 0, content.Length);
            }
        }

 

c# Newtonsoft.Json封装

标签:HERE   string   json   oid   ring   []   serialize   serial   convert   

原文地址:https://www.cnblogs.com/yuanzijian-ruiec/p/9720881.html


评论


亲,登录后才可以留言!