转载:http://www.cnblogs.com/ejiyuan/archive/2010/04/09/1708084.html
方法一:引入System.Web.Script.Serialization命名空间使用 JavaScriptSerializer类实现简单的序列化
序列化类:Personnel
public class Personnel
{
public int Id { get; set; }
public string Name { get; set; }
}
执行序列化反序列化:
代码
;
personnel.Name = "小白";
JavaScriptSerializer jsonSerializer = new JavaScriptSerializer();
//执行序列化
string r1 = jsonSerializer.Serialize(personnel);
//执行反序列化
Personnel _Personnel = jsonSerializer.Deserialize<Personnel>(r1);
}