标签:
类名不同,结构相同的两个类相互转换,忽略 实体null值的json转换;
/// <summary> /// 结构相同,类名不同的实体类转换(忽略 null /// kk 2015-06-03 /// </summary> /// <typeparam name="T">需转换的类 类型</typeparam> /// <typeparam name="V">目标类 类型</typeparam> /// <param name="a">需转换的类 对象</param> /// <returns></returns> private V ConvertClassBySameClassStructure<T, V>(T a) where T : class ,new() where V : class,new() { Newtonsoft.Json.JsonSerializerSettings jSetting = new Newtonsoft.Json.JsonSerializerSettings(); jSetting.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore; string json = Newtonsoft.Json.JsonConvert.SerializeObject(a, jSetting); return SerializeUtil.DeserializeJson<V>(json); }
标签:
原文地址:http://www.cnblogs.com/systemkk/p/4548277.html