1.設置JSON-LIB讓其過濾掉引起循環的字段。

Java代碼 復制代碼 代碼如下: JsonConfig config = new JsonConfig(); config.setIgnoreDefaultExcludes(false); config.setCycleDetectionStrategy(CycleDe " /> 国产主播喷水一区二区,最近中文字幕一区二区三区,国产精品毛片一区二区三区

色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

json-lib出現There is a cycle in the hierarchy解決辦法

解決辦法

1.設置JSON-LIB讓其過濾掉引起循環的字段。

Java代碼
復制代碼 代碼如下:
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[]{//只要設置這個數組,指定過濾哪些字段。
"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[]{//只要設置這個數組,指定過濾哪些字段。 "consignee", "contract", "coalInfo", "coalType", "startStation", "balanceMan", "endStation" }); String tempStr = "{/"TotalRecords/":"+ total.toString() +",/"Datas/":"+JSONSerializer.toJSON(list,config).toString()+"}"; out.print(tempStr);

2.設置JSON-LIB的setCycleDetectionStrategy屬性讓其自己處理循環,省事但是數據過于復雜的話會引起數據溢出或者效率低下。
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);

JavaScript技術json-lib出現There is a cycle in the hierarchy解決辦法,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 大丰市| 曲阳县| 梓潼县| 囊谦县| 永昌县| 嘉定区| 锡林郭勒盟| 靖西县| 界首市| 洛隆县| 丹江口市| 台前县| 永清县| 西林县| 兰坪| 南宫市| 集贤县| 周口市| 高陵县| 静乐县| 淮阳县| 聂荣县| 江北区| 易门县| 增城市| 阜阳市| 莱阳市| 东乡县| 卓尼县| 海丰县| 鄂托克旗| 黄骅市| 华容县| 山东| 桃园县| 和龙市| 兴山县| 沾益县| 攀枝花市| 南涧| 阿勒泰市|