C# json object互转工具

时间:2023-12-29 13:39:14
public static T Deserializer<T>(string path)
{
try
{
System.Xml.XmlDocument xd = new System.Xml.XmlDocument();
xd.LoadXml(path);
MemoryStream stream = new MemoryStream();
xd.Save(stream); XmlSerializer xml = new XmlSerializer(typeof(T));
//序列化对象
T t = (T)xml.Deserialize(stream);
stream.Close();
return t;
}
catch (InvalidOperationException)
{
throw;
}
catch (FileNotFoundException)
{ throw; }
finally
{ }
}

https://jsonclassgenerator.codeplex.com/

http://json2csharp.com/