public IHttpActionResult OrgTree() { try { StringBuilder json = new StringBuilder(); OrganizeService os = new OrganizeService(); var list = os.Tree(0); json.Append("["); foreach (var item in list.Where(t => t.pid == 0)) { json.Append("{\"nodeid\":" + item.id + ",\"parentid\":" + item.pid + ",\"label\":\"" + item.title + "\",\"isedit\":false,\"children\":[" + SubOrg(list, item).ToString() + "]},"); } if (list.Count(t => t.pid == 0) > 0) { json.Remove(json.Length - 1, 1); } json.Append("]"); return(Json(new { code = 1, msg = "ok", data = json.ToString(), nodeid = list.Max(t => t.id) + 1 })); } catch (Exception e) { return(Json(new { code = 0, msg = e.Message })); } }