|
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è)置這個數(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è)置這個數(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ù)雜的話會引起數(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);
JavaScript技術(shù):json-lib出現(xiàn)There is a cycle in the hierarchy解決辦法,轉(zhuǎn)載需保留來源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時(shí)間聯(lián)系我們修改或刪除,多謝。