最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

json-lib出現(xiàn)There is a cycle in the hierarchy解決辦法

 更新時(shí)間:2010年02月24日 19:17:41   作者:  
如果需要解析的數(shù)據(jù)間存在級(jí)聯(lián)關(guān)系,而互相嵌套引用,在hibernate中極容易嵌套而拋出net.sf.json.JSONException: There is a cycle in the hierarchy異常。
解決辦法

1.設(shè)置JSON-LIB讓其過濾掉引起循環(huán)的字段。

Java代碼
復(fù)制代碼 代碼如下:

JsonConfig config = new JsonConfig();
config.setIgnoreDefaultExcludes(false);
config.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
config.registerJsonValueProcessor(Date.class,new DateJsonValueProcessor("yyyy-MM-dd")); //date processor register
config.setExcludes(new String[]{//只要設(shè)置這個(gè)數(shù)組,指定過濾哪些字段。
"consignee",
"contract",
"coalInfo",
"coalType",
"startStation",
"balanceMan",
"endStation"
});
String tempStr = "{\"TotalRecords\":"+ total.toString() +",\"Datas\":"+JSONSerializer.toJSON(list,config).toString()+"}";
out.print(tempStr);
JsonConfig config = new JsonConfig();
config.setIgnoreDefaultExcludes(false);
config.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
config.registerJsonValueProcessor(Date.class,new DateJsonValueProcessor("yyyy-MM-dd")); //date processor register
config.setExcludes(new String[]{//只要設(shè)置這個(gè)數(shù)組,指定過濾哪些字段。 "consignee", "contract", "coalInfo", "coalType", "startStation", "balanceMan", "endStation" }); String tempStr = "{\"TotalRecords\":"+ total.toString() +",\"Datas\":"+JSONSerializer.toJSON(list,config).toString()+"}"; out.print(tempStr);

2.設(shè)置JSON-LIB的setCycleDetectionStrategy屬性讓其自己處理循環(huán),省事但是數(shù)據(jù)過于復(fù)雜的話會(huì)引起數(shù)據(jù)溢出或者效率低下。
Java代碼
[code]
JsonConfig config = new JsonConfig();
config.setIgnoreDefaultExcludes(false);
config.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT);
config.registerJsonValueProcessor(Date.class,new DateJsonValueProcessor("yyyy-MM-dd")); //date processor register
String tempStr = "{\"TotalRecords\":"+ total.toString() +",\"Datas\":"+JSONSerializer.toJSON(list,config).toString()+"}";
out.print(tempStr);

相關(guān)文章

  • JSON與XML優(yōu)缺點(diǎn)對(duì)比分析

    JSON與XML優(yōu)缺點(diǎn)對(duì)比分析

    本文從各個(gè)方面向大家對(duì)比展示了json和xml的優(yōu)缺點(diǎn),十分的全面細(xì)致,有需要的小伙伴可以參考下。
    2015-07-07
  • 最新評(píng)論

    苍山县| 政和县| 新密市| 涿鹿县| 宣武区| 彭水| 嘉峪关市| 得荣县| 澄城县| 玉溪市| 保亭| 峨眉山市| 溧水县| 磐安县| 漳平市| 醴陵市| 桃江县| 金沙县| 兴文县| 治多县| 广平县| 竹北市| 华坪县| 东阿县| 瓦房店市| 贵州省| 舟山市| 周口市| 大埔区| 高尔夫| 维西| 连城县| 扶绥县| 新沂市| 芦山县| 利津县| 德化县| 吉隆县| 体育| 高唐县| 潢川县|