[{text: '广州三号公司', cls: 'folder',iconCls: 'icon-company',expanded: false,children: [{text: '正式车辆(7辆)',cls: 'folder',expanded: false,children:[{text: 'MY0001(行驶)',id:'MY0001', leaf: true,checked: false},{text: 'MY0002(行驶)',id:'MY0002', leaf: true,checked: false},{text: 'MY0004(行驶)',id:'MY0004', leaf: true,checked: false},{text: 'MY0008(行驶)',id:'MY0008', leaf: true,checked: false},{text: 'MY0009(行驶)',id:'MY0009', leaf: true,checked: false},{text: 'MY0011(行驶)',id:'MY0011', leaf: true,checked: false},{text: 'MY0013(行驶)',id:'MY0013', leaf: true,checked: false}]}]}];

解决方案 »

  1.   

    所有的键也要套""
    比如
    'text': '广州三号公司'
      

  2.   

    如果你是用了json插件去转换这些数据的话,你应该把key和value都用双引号括起来。
      

  3.   

    JSON没其他任何问题了
    引号也确实是问题
    我要看你代码了 哈哈~
      

  4.   


       public void vehicleTree(){
       response.setContentType("text/html; charset=UTF-8");
    try {
     String queryString="select new com.ym.gps.vo.VehicleInfoTreeForm(v.vehicleNo,c.fullName)  from VehicleInfo v,CompanyInfo c where v.vehicleCompanyID=c.id and c.id=3";
         List<VehicleInfoTreeForm> list =  (List<VehicleInfoTreeForm>) vehicleInfoManager.findListByQueryString(queryString);
    PrintWriter out =  response.getWriter();
    String str = "[{text: '"+list.get(0).getText()+"',id:'001',cls: 'folder',iconCls: 'icon-company',expanded: false,children:[{text: '正式车辆("+list.size()+"辆)',cls: 'folder',expanded: false,children:[";
    for(VehicleInfoTreeForm vehicleInfo :list){
    str += "{text: '<span style=color: green;>"+vehicleInfo.getId()+"(行驶)</span>',id:'"+vehicleInfo.getId()+"', leaf: true,checked: false},";

    }
    str = str.substring(0,str.length()-1);
    str += "]}]}];";

    out.print(str);
    }catch (Exception e) {
    e.printStackTrace();
      }
       
       }
      

  5.   

    另外,我直接写死加载的树的代码是可以出来的..
    var carTreeData = [{
        text: '明业运输有限公司(5辆)',
        cls: 'folder',
        iconCls: 'icon-company',
        children: [{
            text: '测试车辆(5辆)',
            cls: 'folder',
            children: [{
                text: '<span style="color: green;">MY0001(行驶)</span>',
                id:'MY0001',
                leaf: true,
                checked: false
            },{
                text: '<span style="color: red;">MY0002(熄火)</span>',
                id:'MY0002',
                leaf: true,
                checked: false
            },{
                text: '<span style="color: green;">MY0003(行驶)</span>',
                id:'MY0003',
                leaf: true,
                checked: false
            },{
                text: '<span style="color: yellow;">MY0004(停车)</span>',
                id:'MY0004',
                leaf: true,
                checked: false
            },{
                text: '<span style="color: green;">MY0005(行驶)</span>',
                id:'MY0005',
                leaf: true,
                checked: false
            },{
                text: '<span style="color: yellow;">MY0006(停车)</span>',
                id:'MY0006',
                leaf: true,
                checked: false
            }]
        },{
         text: '别的分类(0辆)',
         leaf: true
        }]
    }];
      

  6.   

    前台很简单var comtree = new Ext.tree.TreePanel({
        frame:true,
        layout :'fit',
        width : 300,
    height: 200,
        animate:false,
        rootVisible:false,
        enableDD:true,
        containerScroll: true,
        loader: new Ext.tree.TreeLoader({
            dataUrl:'vehicleInfo!vehicleTree.action'
        })
    });
      

  7.   

    encodeURI('vehicleInfo!vehicleTree.action')
    试试
      

  8.   

    Valid JSON[
        {
            "text": "广州三号公司",
            "cls": "folder",
            "iconcls": "icon-company",
            "expanded": "false",
            "children": [
                {
                    "text": "正式车辆(7辆)",
                    "cls": "folder",
                    "expanded": "false",
                    "children": [
                        {
                            "text": "MY0001(行驶)",
                            "id": "MY0001",
                            "leaf": "true",
                            "checked": "false" 
                        },
                        {
                            "text": "MY0002(行驶)",
                            "id": "MY0002",
                            "leaf": "true",
                            "checked": "false" 
                        },
                        {
                            "text": "MY0004(行驶)",
                            "id": "MY0004",
                            "leaf": "true",
                            "checked": "false" 
                        },
                        {
                            "text": "MY0008(行驶)",
                            "id": "MY0008",
                            "leaf": "true",
                            "checked": "false" 
                        },
                        {
                            "text": "MY0009(行驶)",
                            "id": "MY0009",
                            "leaf": "true",
                            "checked": "false" 
                        },
                        {
                            "text": "MY0011(行驶)",
                            "id": "MY0011",
                            "leaf": "true",
                            "checked": "false" 
                        },
                        {
                            "text": "MY0013(行驶)",
                            "id": "MY0013",
                            "leaf": "true",
                            "checked": "false" 
                        } 
                    ] 
                } 
            ] 
        }
    ]
      

  9.   

    看你的json 格式是对的。
    你最好自己调试一下,看看问题究竟出在哪?
    firefox 用firebug 调试
    ie 下,vs支持js 调试的我估计是loader: new Ext.tree.TreeLoader({
      dataUrl:'vehicleInfo!vehicleTree.action'
      })这个可能有问题,new Ext.tree.TreeLoader 是一个函数,接受一个js对象,你服务器返回的是json 格式的字符串!还有,你调试一下,看看服务器返回的json 字符串是否正确。 用eval 把json 字符串转成js 对象!
    看你的json 字符串后面有一个“;”号。这样转换时会出错!