I'm working with jquery orgchart, and i want to save the changes of my chart to database, orgchart has a method to get the modified tree structure getHierarchy(). The problem is how to parse the JSON and save to database.
DEMO JSON:
{
"id": "1",
"children": [
{
"id": "40",
"children": [
{
"id": "53"
}
]
},
{
"id": "57",
"children": [
{
"id": "72",
"children": [
{
"id": "73"
}
]
}
]
}
]
}
I want something like a flat Array to an easy update in DB
(
[0] => Array
(
[id] => 1
[parentid] => 0
)
[1] => Array
(
[id] => 40
[parentid] => 1
)
[2] => Array
(
[id] => 53
[parentid] => 40
)
[3] => Array
(
[id] => 57
[parentid] => 1
)
[4] => Array
(
[id] => 72
[parentid] => 57
)
[5] => Array
(
[id] => 73
[parentid] => 72
)
)