树形结构的json数据源,
转package test;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import com.baihe.entity.Node;
public class bd {
List nodeList =new ArrayList();
bd(){//构造方法里初始化模拟List
Node node1 = new Node("01","0");
Node node2 = new Node("0102","01");
Node node3 = new Node("0103","01");
Node node4 = new Node("010201","0102");
Node node5 = new Node("010202","0102");
nodeList.add(node1);
nodeList.add(node2);
nodeList.add(node3);
nodeList.add(node4);
//nodeList.add(node5);
}
StringBuffer returnStr=new StringBuffer();
public void recursionFn(List list , Node node){
if(hasChild(list,node)){
returnStr.append("{id:");
returnStr.append(node.getId());
returnStr.append(",parentId:");
returnStr.append(node.getParentId());
returnStr.append(",children:[");
List childList = getChildList(list,node);
Iterator it = childList.iterator();
while(it.hasNext()){
Node n = (Node)it.next();
recursionFn(list,n);
}
returnStr.append("]},");
}else{
returnStr.append("{id:");
returnStr.append(node.getId());
returnStr.append(",parentId:");
returnStr.append(node.getParentId());
returnStr.append(",leaf:true},");
&