..
using System.Runtime.Serialization.Json;(要添加 System.ServiceModel.Web引用)
实体类
YunQiData model = new YunQiData();
model.AddDate = DateTime.Now.ToString();
model.Amount = 100;
model.PPlatformID = 100;
model.SID = 100;
model.UID = "2";
序列化与化序列化
DataContractJsonSerializer ds = new DataContractJsonSerializer(typeof(YunQiData));
using (MemoryStream ms = new MemoryStream())
{
ds.WriteObject(ms,model);
string output = Encoding.UTF8.GetString(ms.ToArray());
Console.WriteLine(output);
var ser = new DataContractJsonSerializer(typeof(YunQiData));
var ms2 = new MemoryStream(Encoding.UTF8.GetBytes(output));
YunQiData myClass1 = (YunQiData)ser.ReadObject(ms2);
if (myClass1 != null)
{
//doing
} }
原文链接:https://www.f2er.com/json/290783.html