【发布时间】:2012-02-17 22:58:54
【问题描述】:
作为输入,我列出了每个对象具有属性的所有对象:
- 姓名
- children(object.children 是所有孩子的列表)
- 父级(如果对象是顶级则为空)
如何正确使用 Groovy JSONBuilder 来渲染这些数据(树的深度是无限的):
-Object 1
--Object 1.1
---Object 1.1.1
--Object 1.2
-Object 2
JSON 格式应该是这样的:
[
{
"name":"Object1",
"children":[
{
"name":"Object1.1",
"children":[
{
"name":"Object 1.1.1",
"children":[]
}
]
},
{
"name":"Object1.2",
"children":[]
}
]
},
{
"name":"Object2","children":[]
}
]
这是为将显示此树的 extJS 组件构建 JSON 所必需的。感谢您的帮助!
【问题讨论】: