Json序列化、反序列化互换

 

// 序列化
using (MemoryStream stream = new MemoryStream())
{
serializer.WriteObject(stream, hdm);
jsonText = Encoding.UTF8.GetString(stream.ToArray());
//Console.WriteLine(jsonText);
}
// 反序列化
using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonText)))
{
DataContractJsonSerializer serializer1 = new DataContractJsonSerializer(typeof(AnesMS.DataModel.ByEntity._4Statistics.HISDataModel));

AnesMS.DataModel.ByEntity._4Statistics.HISDataModel hdm1 = (AnesMS.DataModel.ByEntity._4Statistics.HISDataModel)serializer1.ReadObject(ms);
return hdm1;
}

posted on 2013-11-08 14:48  张晓鹏  阅读(156)  评论(0编辑  收藏  举报