Bytes Object with Json Converter - CSharp Newtonsoft.Json

CSharp examples for Newtonsoft.Json:JsonConvert.DeserializeObject

Description

Bytes Object with Json Converter

Demo Code


using System.Threading.Tasks;
using System.Linq;
using System.Collections.Generic;
using System;//  w w  w . ja  v  a 2s .  c  o  m
using Newtonsoft.Json;

public class Main{

        public static T Bytes2Object<T>(byte[] buff)
        {
            string json = System.Text.Encoding.UTF8.GetString(buff);
            return JsonConvert.DeserializeObject<T>(json);
        }

        public static object Bytes2Object(byte[] buff)
        {
            string json = System.Text.Encoding.UTF8.GetString(buff);
            return JsonConvert.DeserializeObject<object>(json);
        }
}

Related Tutorials