$tree[0]['text']='a';
$tree[0]['son_nor']='b%c';
$tree[1]['text']='b';
$tree[1]['son_nor']='d';
$tree[2]['text']='c';
$tree[2]['son_nor']='-1';
$tree[3]['text']='d';
$tree[3]['son_nor']='-1';
function buildtree($node)
{
global $tree;
for ($i=0; $i<count($tree); $i++)
{
if ($tree[$i]['text']==$node)
{
$tmptree['text']=$node;
$tmptree['nodes']=array();
$str=$tree[$i]['son_nor'];
//echo json_encode($tmptree).'</br>';
if ($str!='-1')
{
$child=explode('%', $str);
for($j=0;$j<count($child);$j++)
{
$tmptree['nodes'][]=buildtree($child[$j]);
}
}
return $tmptree;
}
}
}
echo json_encode('[{"text":"a","nodes":"1"},{"text":"v"}]');