1 My Documents 0
2 photos 1
3 Friend 2
4 Wife 2
5 Company 2
6 Program Files 1
7 Intel 6
8 Java 6
数据库中是以上结构,如何写段代码生成如下结构的json数据?
[{
"id":1,
"text":"My Documents",
"children":[{
"id":2,
"text":"Photos",
"children":[{
"id":3,
"text":"Friend"
},{
"id":4,
"text":"Wife"
},{
"id":5,
"text":"Company"
}]
},{
"id":6,
"text":"Program Files",
"children":[{
"id":7,
"text":"Intel"
},{
"id":8,
"text":"Java",
}]
}]
}]