.net4 json格式数基本操作
//读取JSON格式数据
public static object readData(Type tt, byte[] data, int lon)
{
try
{
var clientData = new DataContractJsonSerializer(tt);
return clientData.ReadObject(new MemoryStream(data, 0, lon));
}
catch
{
throw new Exception("格式错误");
}
}
//写入数据
public static byte[] writeData(Type tt, object dataS)
{
var ms = new MemoryStream();
var dcjs = new DataContractJsonSerializer(tt);
dcjs.WriteObject(ms, dataS);
return ms.ToArray();
}