日期:2014-05-19  浏览次数:20666 次

net.sf.json.JSONException: There is a cycle in the hierarchy!
struts2.1.8 中json格式转换问题:需要的7个包全部导入——只是commons-lang-2.4.jar 我用的是commons-lang-2.3.jar。这个应该没问题吧!
我的配置跟页面都没有问题~~~!因为下面的测试可以正常提交跟响应!
但是在执行这一句的时候(this.getMgrMeetingList()返回的是list集合):
Java code
JSONObject json = JSONObject.fromObject(this.getMgrMeetingList());

有错:
Java code
net.sf.json.JSONException: There is a cycle in the hierarchy!

网上查了一下:说是Hibernate关联属性的问题、也修改了一些代码、但是就是不行!
我的action代码:
Java code

//获取会议室编号
        String meet = request.getParameter("meetId");
        JsonConfig config = new JsonConfig();
        config.setJsonPropertyFilter(new PropertyFilter(){
            public boolean apply(Object source, String name, Object value) {
                if(name.equals("tbmeetroom") || "tbmeetroom" == name
                        || name.equals("tbmeettype") || "tbmeettype" == name
                        ||name.equals("tbmeetfiles") || "tbmeetfiles" == name
                        || name.equals("tbmeetpersons") || "tbmeetpersons" == name ) {
                    
                    return true;
                    
                } else {
                    
                    return false;
                    
                }
            }
        });
        //如果会议编号不为空
        if(null !=meet && !"".equals(meet)){
            //创建获取星期日期对象
            TimeTake time = new TimeTake();
            //调用查询方法
            this.setMgrMeetingList(mgrService.getMgrByTime(Long.valueOf(meet), time.getTime()));  
        }        
        //创建json对象
        JSONObject json = JSONObject.fromObject(this.getMgrMeetingList(),config);
        result = json.toString();
        System.out.println(result);
        return SUCCESS;



我的属性文件:
XML code

<many-to-one name="tbmeetroom" class="com.boxun.crm.dao.entities.Tbmeetroom" fetch="select">
            <column name="HUIYISHI" precision="22" scale="0">
                <comment>会议室,外键,和会议室管理主键ID对应</comment>
            </column>
        </many-to-one>
        <many-to-one name="tbmeettype" class="com.boxun.crm.dao.entities.Tbmeettype" fetch="select">
            <column name="LEIXING" precision="22" scale="0">
                <comment>会议类型,外键,和会议类型表的主键ID相关联</comment>
            </column>
        </many-to-one>

 <set name="tbmeetfiles" inverse="true">
            <key>
                <column name="MEETID" precision="22" scale="0">
                    <comment>外键,和会议管理主键ID对应</comment>
                </column>
            </key>
            <one-to-many class="com.boxun.crm.dao.entities.Tbmeetfile" />
        </set>
        <set name="tbmeetpersons" inverse="true">
            <key>
                <column name="MEETID" precision="22" scale="0">
                    <comment>外键,和会议管理主键ID对应</c