Newtonsoft.Json 4.5.11

来源:互联网 发布:蓝胖升级数据 编辑:程序博客网 时间:2024/05/22 12:49
 static void Main(string[] args)        {            string jsonText = "[{\"a\":\"aaa\",\"b\":\"bbb\",\"c\":\"ccc\"},{\"a\":\"aaa2\",\"b\":\"bbb2\",\"c\":\"ccc2\"}]";            //JArray ja = (JArray)JsonConvert.DeserializeObject(jsonText);            //JObject o = (JObject)ja[1];            //Console.WriteLine(o["a"]);//aaa2            //Console.WriteLine(ja[1]["a"]);//aaa2            List<Customer> _list = JsonConvert.DeserializeObject<List<Customer>>(jsonText);            Console.WriteLine(_list[1].a);//aaa2            foreach (Customer c in _list)            {                Console.WriteLine(c.c);            }            Console.ReadLine();        }
 public class Customer    {        //在序列化前后没有变动          public string a { get; set; }        //在序列化前后设置和重置          public string b { get; set; }        //设置为null,但在序列化后填充          public string c { get; set; }        public string Other { get; set; }        public Customer()        {            //              //TODO: 在此处添加构造函数逻辑              //              a = "";            b = "";            c = "";            Other = null;        }    }


0 0