Linq To Json

using Newtonsoft.Json.Linq;
        /// <summary>
        ///     递归生成部门树
        /// </summary>
        /// <param name="depList">部门列表</param>
        /// <param name="parentId">用户部门的父级部门Id</param>
        /// <returns></returns>
        private JArray ConvertDepartTree(IList<AspSysDepartmentDto> depList, int parentId)
        {
            var jArray = new JArray(from a in depList
                                    where a.ParentId == parentId
                                    select new JObject(
                                        new JProperty("id", a.Id),
                                        new JProperty("text", a.Name),
                                        new JProperty("children", ConvertDepartTree(depList, a.Id)
                                        )));
            return jArray;
        }

JSON.net Linq  To Json文档地址:https://www.newtonsoft.com/json/help/html/CreatingLINQtoJSON.htm

posted @ 2019-01-23 11:44  _York  阅读(360)  评论(1编辑  收藏  举报