您好,欢迎访问一九零五行业门户网

C# Json 序列化与反序列化一

public class jsonserializer { /// <summary> /// json序列化 /// </summary> /// <typeparam name="t"></typeparam> /// <param name="t"></param> /// <returns></returns> public static string jsonstringserializer<t>(t t) { datacontractjsonserializer ser = new datacontractjsonserializer(typeof(t)); using (memorystream ms = new memorystream()) { ser.writeobject(ms, t); string json = encoding.utf8.getstring(ms.toarray()); ms.close(); return json; } } /// <summary> /// json反序列化 /// </summary> /// <typeparam name="t"></typeparam> /// <param name="json"></param> /// <returns></returns> public static t dejsonserializer<t>(string json) { datacontractjsonserializer ser = new datacontractjsonserializer(typeof(t)); using (memorystream ms = new memorystream(encoding.utf8.getbytes(json))) { object obj=ser.readobject(ms); ms.close(); if (obj == null) { throw new notimplementedexception("序列化实体为null,json:" + json); } return (t)obj; } } }
josn序列化与反序列化demo
c# json 序列化与反序列化二
以上就是c# json 序列化与反序列化一的内容。
其它类似信息

推荐信息