C# json系列化和反系列化

  经此一役,深感知识储备竟是如此之重要,由于对系列化和反系列化之不足,导致浪费了大把时间和精力在无用之功上。由此观之,将所学所写所感记录是必要的。

进入正题:

json类:

public class interfaceName
    {
        [JsonProperty("name")]
        public string name;
        [JsonProperty("children")]
        public List<inputData> dataList = new List<inputData>();
    }

系列化:

string json = JsonConvert.SerializeObject(treeList);

反系列化:

string test = "[{"name":"1111","children":[]}]";

List<interfaceName> two = JsonConvert.DeserializeObject<List<interfaceName>>(test);

简单吗?Newtonsoft.Json一句话搞定。在看看我写了半天的东西

你妹!这不是瞎耽误功夫吗?

原文地址:https://www.cnblogs.com/ganzhihui/p/10188837.html