请教“实体类一个反序列化的方法”怎么写成一个通用的方法,将实体类传过来
请教:以下这两个方法完全一样,就是每一个实体类一个反序列化的方法,怎么写成一个通用的方法,将实体类传过来使用?
public static List<BaseServiceRef.tbasemenufunction> Deserialize_MenuFunc(string _JsonText)
{
string s = ReleaseXmlTag(_JsonText);
List<BaseServiceRef.tbasemenufunction> _Test = new List<BaseServiceRef.tbasemenufunction>();
DataContractJsonSerializer _Json = new DataContractJsonSerializer(_Test.GetType());
byte[] _Using = System.Text.Encoding.UTF8.GetBytes(s);
System.IO.MemoryStream _MemoryStream = new System.IO.MemoryStream(_Using);
_MemoryStream.Position = 0;
_Test = (List<BaseServiceRef.tbasemenufunction>)_Json.ReadObject(_MemoryStream);
return _Test;
}
public static List<BaseServiceRef.tbasefunctiongrant> Deserialize_UserGrant(string _JsonText)
{
string s = ReleaseXmlTag(_JsonText);
List<BaseServiceRef.tbasefunctiongrant> _Test = new List<BaseServiceRef.tbasefunctiongrant>();
DataContractJsonSerializer _Json = new DataContractJsonSerializer(_Test.GetType());
byte[] _Using = System.Text.Encoding.UTF8.GetBytes(s);
System.IO.MemoryStream _MemoryStream = new System.IO.MemoryStream(_Using);
_MemoryStream.Position = 0;
_Test = (List<BaseServiceRef.tbasefunctiongrant>)_Json.ReadObject(_MemoryStream);
return _Test;
}
------解决方案--------------------可以用泛形:
public static T JsonDeserialize<T>(string json)
{
DataContractJsonSerializer zer = new DataContractJsonSerializer(typeof(T));
using (MemoryStream ms =