C# Json对象数组复杂JObject 序列化

tatic void Main(string[] args)
        {
            //先反序列化看看
            string json = "{\"name\": true,\"age\": \"success\",\"hobby\": [{\"obj1\": \"6\",\"obj2\": \"7\",\"obj3\": \"10\"}, {\"obj1\": \"6\",\"obj2\": \"7\",\"obj3\": \"10\"}]}";
            var q = JsonConvert.DeserializeObject<dynamic>(json);
            Console.WriteLine(q.name);
 
            //只反序列化hobby为List<Test>
            JObject jobj = JObject.Parse(json);
            string Data = jobj["hobby"].ToString();
            var v = JsonConvert.DeserializeObject<List<Test>>(Data);
            Console.WriteLine(v[0].obj2);
 
            Console.ReadLine();
        }
 
        public class Test
        {
            public string obj1 { get; set; }
            public string obj2 { get; set; }
            public string obj3 { get; set; }
        }                

 

posted @ 2020-07-05 10:52  netlock  阅读(1514)  评论(0编辑  收藏  举报