标签:
///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;
}
}
标签:
原文地址:http://www.cnblogs.com/lyy445910200/p/5830502.html