1 //data 是个二进制的数据流,序列化成对于的实体类型,实体类型就被赋值了。
var so = (Models.VWMSSO)JsonConvert.DeserializeObject(Encoding.UTF8.GetString(data), typeof(Models.VWMSSO));
2 如同3中的obj
将封装的JSon可以序列划成对于的xmldocument的类型
XmlDocument doc = JsonConvert.DeserializeXmlNode(JsonConvert.SerializeObject(obj));
3 序列化内容进行请求
var Obj = new JObject
{
{"head", new JObject
{
{ "transCode", "A1001" },
{ "transId", transid }
}
},
{"body", new JObject
{
}
}
};
//每次都请求下新的token
//StringContent 的命名空间是System.Net.Http,是可以用于呼叫接口时用于携带内容
HttpContent contenttoken = new StringContent(JsonConvert.SerializeObject(Obj), Encoding.UTF8, "application/json");
var messagetoken = await _httpClientFactory.CreateClient().PostAsync(tokenUrl, contenttoken);
JsonConvert.SerializeObject 这个是序列化成string 类型。就是json的文本类型
JsonConvert.Deserializexxx 反序列化,就是把json序列化成自己需要的其他非json的类型,Eg:1和2
JObject o = new JObject(
new JProperty("v", "1.0"),
new JProperty("timestamp", (new DateTimeOffset(DN.DeliveryDateTime).ToUnixTimeMilliseconds()).ToString()),
new JProperty("method", "delivery"),
new JProperty("format", "json"),
new JProperty("flag", account),
new JProperty("order", OrderSn),
new JProperty("Number", Number),
new JProperty("logistics", ExpressCode),
new JProperty("mfrom", "总店()"));
string s = Newtonsoft.Json.JsonConvert.SerializeObject(o);
//下面这个就是将s 反序列成Dictionary<string,string>的字典的类型。
Dictionary<string, string> values = Newtonsoft.Json.JsonConvert.DeserializeObject<Dictionary<string, string>>(s);
string ss = GetSignature(values, secret);
o.Add(new JProperty("sign", ss));
Json = JsonConvert.SerializeObject(reqdata)//这个是将实体对象序列化成Json