SQL 数据库 要生成下面的JSON 树
<script type='text/javascript'>
var jsonData = [{
"id": 1,
"name": "企业主体信用得分",
"pid": null,
"children": [
{
"id": 2,
"name": "企业素质",
"pid": 1,
"children": [
{
"id": 5,
"name": "基本信息",
"pid": 2,
"children": [
{
"id": 10,
"name": "企业主体信息识别",
"pid": 5,
"children": [
]
},
{
"id": 11,
"name": "企业持续注册时间",
"pid": 5,
"children": [
]
},
{
"id": 12,
"name": "注册资本",
"pid": 5,
"children": [
]
}
]
},
{
"id": 6,
"name": "管理认证",
"pid": 2,
"children": [
{
"id": 13,
"name": "国际性管理认证",
"pid": 6,
"children": [
]
}
]
}
]
},
{
"id": 3,
"name": "履约记录",
"pid": 1,
"children": [
{
"id": 7,
"name": "税务执行情况",
"pid": 3,
"children": [
{
"id": 14,
"name": "是否按时缴纳税款",
"pid": 7,
"children": [
]
}
]
},
{
"id": 8,
"name": "网贷情况",
"pid": 3,
"children": [
{
"id": 15,
"name": "网贷逾期",
"pid": 8,
"children": [
]
}
]
}
]
},
{
"id": 4,
"name": "公共监督",
"pid": 1,
"children": [
{
"id": 9,
"name": "行政处罚",
"pid": 4,
"children": [
{
"id": 16,
"name": "处罚信息",
"pid": 9,
"children": [
]
}
]
}
]
}
]
}
];
数据库内容是一个部门的组织架构
要怎么写啊 请教高手