首页 > Web开发 > 详细

list转json和json转list

时间:2016-09-01 18:19:04      阅读:269      评论:0      收藏:0      [点我收藏+]

 

///json转list

public static List<TaskActionParameterElement> JsonToList<TaskActionParameterElement>(string JsonStr)
{
JavaScriptSerializer Serializer = new JavaScriptSerializer();
List<TaskActionParameterElement> objs = Serializer.Deserialize<List<TaskActionParameterElement>>(JsonStr);
return objs;
}

/// <summary>
/// list转json
/// </summary>
public static string ListToJson<TaskActionParameterElement>(TaskActionParameterElement data)
{
try
{
System.Runtime.Serialization.Json.DataContractJsonSerializer serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(data.GetType());
using (MemoryStream ms = new MemoryStream())
{
serializer.WriteObject(ms, data);
return Encoding.UTF8.GetString(ms.ToArray());
}
}
catch
{
return null;
}
}

list转json和json转list

原文:http://www.cnblogs.com/lyy445910200/p/5830502.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!