首页 > 代码库 > C# 获取嵌套json

C# 获取嵌套json

如下这种嵌套json,需要声明两个类来进行反序列化(Deserialize)

 

{   "errcode": 0,   "errmsg": "ok",   "department": [       {           "id": 2,           "name": "广州研发中心",           "parentid": 1       },       {           "id": 3           "name": "邮箱产品部",           "parentid": 2       }   ]}

 

 

声明的类如下

 

    public class deptinfo    {        public string errcode = string.Empty;        public string errmsg = string.Empty;        public List<department> department = new List<department>();    }    public class department    {        public int id;        public int parentid;        public string name = string.Empty;    }

 

 

反序列化时,写法示例如下

 

   JavaScriptSerializer js = new JavaScriptSerializer();   deptinfo info= js.Deserialize<deptinfo>(strResult);

 

C# 获取嵌套json