.NET微信公众号查看关注者接口(2)

public class JsonEntityExchange<T> where T:new() { /// <summary> /// json转实体LIST /// </summary> /// <param></param> /// <returns></returns> public static List<T> Json2Entitys(string JsonStr) { JavaScriptSerializer Serializer = new JavaScriptSerializer(); List<T> objs = Serializer.Deserialize<List<T>>(JsonStr); return objs; } /// <summary> /// json转实体 /// </summary> /// <param></param> /// <returns></returns> public static T Json2Entity(string json) { T obj = Activator.CreateInstance<T>(); using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(json))) { DataContractJsonSerializer serializer = new DataContractJsonSerializer(obj.GetType()); return (T)serializer.ReadObject(ms); } } /// <summary> /// 实体转json /// </summary> /// <param>实体list</param> /// <returns></returns> public static string Entity2Json(List<T> lists) { return new JavaScriptSerializer().Serialize(lists); } }

结果如图:

.NET微信公众号查看关注者接口

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wjyggs.html