asp.net mvc 对象和集合序列化
2020-12-13 14:42
标签:get 使用 name for c io private List organizations.Add(new Model.Organization.Organization organizations.Add(new Model.Organization.Organization private void AttachChildren(TreeModel tree, List var organizationsTmp = organizations.Where(p => !string.IsNullOrEmpty(p.ParentId) && p.ParentId.Equals(tree.id)).ToList(); public IList this.AttachChildren(tree, organizations); 如果GetTree返回的是集合,则Controler调用GetTree序列化为json以后为: 如果GetTree返回的是对象,则Controler调用GetTree序列化为json以后为: asp.net mvc 对象和集合序列化,搜素材,soscw.com asp.net mvc 对象和集合序列化 标签:get 使用 name for c io 原文地址:http://www.cnblogs.com/bygrace/p/3794776.html
{
var organizations = new List
{
Id = "1",
Name = "一汽",
});
{
Id = "2",
Name = "红旗",
ParentId = "1"
});
organizations.Add(new Model.Organization.Organization
{
Id = "3",
Name = "奔腾",
ParentId = "1"
});
organizations.Add(new Model.Organization.Organization
{
Id="4",
Name="奔腾B70",
ParentId="3"
});
return organizations;
}
{
if (Equals(tree, null))
{
return;
}
foreach (Model.Organization.Organization node in organizationsTmp)
{
var t = new TreeModel() {
id=node.Id,
text=node.Name
};
tree.children.Add(t);
this.AttachChildren(t, organizations);
}
}
{
var organizations = this.GetOrganiztions();
var rootNode = organizations.Find(p => string.IsNullOrEmpty(p.ParentId));
var tree = new TreeModel()
{
id = rootNode.Id,
text = rootNode.Name
};
return new List
}[{"id":"1","text":"一汽","children":[{"id":"2","text":"红旗","children":[]},{"id":"3","text":"奔腾","children":[{"id":"4","text":"奔腾B70","children":[]}]}]}]
{"id":"1","text":"一汽","children":[{"id":"2","text":"红旗","children":[]},{"id":"3","text":"奔腾","children":[{"id":"4","text":"奔腾B70","children":[]}]}]}
在asp.net mvc中前端我们可能会经常用到json数组,我们可以考虑使用Json(集合)的方式,这样一来可以不用在前端再去处理