Solution
1. Set the JSON-LIB to let it filter out fields that cause loops.
Java code
Copy codeThe Code is as follows:
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 [] {// you only need to set this array to specify which fields to filter.
"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 [] {// you only need to set this array to specify which fields to filter. "Consignee", "contract", "coalInfo", "coalType", "startStation", "balanceMan", "endStation "}); string tempStr = "{\" TotalRecords \ ":" + total. toString () + ", \" Datas \ ":" + JSONSerializer. toJSON (list, config ). toString () + "}"; out. print (tempStr );
2. Set the setCycleDetectionStrategy attribute of the JSON-LIB to allow it to process loops on its own, saving trouble but too complicated data can cause data overflow or inefficiency.
Java code
[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 );