码迷,mamicode.com
首页 > Web开发 > 详细

list转json和json转list

时间:2016-09-01 18:19:07      阅读:151      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!