一般的反序列化: using Newtonsoft.Json;
invlist = Newtonsoft.Json.JsonConvert.DeserializeObject<FPCYInvList>(data);
反序列化2: using Newtonsoft.Json.Linq;
string sjson = "{\"msg\":\"success\",\"apiNo\":\"1588945692607\",\"code\":0,\"data\":{\"code\":\"0000\",\"message\":\"success\",\"content\":{\"gmrq\":\"2020-04-25 14:24:08\",\"zcsj\":\"2020-04-28 15:05:42\",\"id\":6,\"zczt\":1}}}";
//JObject obj = (JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(sjson);
JObject obj = JObject.Parse(sjson);
textBox1.Text += obj["data"]["content"]["gmrq"].ToString() + "\r\n";
JToken tk = obj["data"];
textBox1.Text += tk["code"].ToString();
序列化:
class AA
{
public string a;
public string b;
}
AA a = new AA();
a.a = "aaa";
a.b = "bbb";
string stra = Newtonsoft.Json.JsonConvert.SerializeObject(a);
//返回:{"a":"aaa","b":"bbb"}