码迷,mamicode.com
首页 > Windows程序 > 详细

c# Newtonsoft.Json封装

时间:2018-09-28 21:20:18      阅读:596      评论:0      收藏:0      [点我收藏+]

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

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

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

        public static void Serialize<T, S>(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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!