如果需要解析的数据间存在级联关系,而互相嵌套引用,在hibernate中极容易嵌套而抛出net.sf.json.JSONException: There is a cycle in the hierarchy异常。
1.设置JSON-LIB让其过滤掉引起循环的字段
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代码
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);
原地址:http://hi.baidu.com/kfo2046/blog/item/f384c5faf9276dd3b58f3172.html
分享到:
相关推荐
如果需要解析的数据间存在级联关系,而互相嵌套引用,在hibernate中极容易嵌套而抛出net.sf.json.JSONException: There is a cycle in the hierarchy异常。
并且对Dao和Service进行了封装,内含.jar包,并且解决了一对多双向关联的could not initialize proxy - no Session错误,同时解决了……invoked on net.sf.json.JSONException: There is a cycle in the hierarchy!...
Memory Hierarchy is a design strategy implemented to bridge the gap between the Central Processing Unit (CPU) and the various types of memory, which have differing speed, capacity, and cost ...
解决这个启动 View Hierarchy时的这个bug: hierarchy viewer unable to debug device
The Lord of the Rings(tm), The Battle for Middle-earth(tm) is a trademark or registered trademark of Electronic Arts in the USA and/or other countries. All rights reserved. LucasArts, the LucasArts ...
conditions is to put a #PRE against the name in the LMHOSTS file. This causes the name to be stored in the name cache when the machine is first initialized, so the name gets resolved without the ...
value for the HEAD symbolic ref when the namespace feature is in use, which has been corrected. * "git am -i --resolved" segfaulted after trying to see a commit as if it were a tree, which has ...
* updated a polygon object: now the polygon toolbar is displayed not near to the object, but in the main toolbar and in ribbon; polygon modes are changed, new modes allow editing and adding curves > ...
在“d3-hierarchy-master”这个项目中,重点在于层次数据(Hierarchy Data)的可视化。层次数据通常表现为树形结构,例如组织架构、文件系统或者生物学的物种分类等。D3提供了hierarchy模块,专门处理这类数据,可以...
the best way to understand how computers work is to build one from scratch, and this textbook leads students through twelve chapters and projects that gradually build a basic hardware platform and a ...
Implementing standard scrolling behavior for a custom CWnd or CDialog-derived class using MFC is fairly non... No change in your inheritance hierarchy is required to use the helper class (CScrollHelper).
### SQL Server 解析 JSON 字符串方法详解 随着 Web 应用和服务的广泛采用,JSON 成为了一种非常流行的轻量级数据交换格式。在 SQL Server 中处理 JSON 数据变得日益重要,尤其是对于那些需要从非结构化数据源提取...
The filesystem is a set of named files, organized in a tree-structured hierarchy of directories, and of operations to manipulate them, as presented in Chapter 7. Files reside on physical media such ...
The manual is a comprehensive guide for engineers, technicians, and maintenance personnel involved in the planning, commissioning, and maintenance of S7-400 systems. It is essential reading for ...
Deep learning is a branch of machine learning where you model the world in terms of a hierarchy of concepts. This pattern of learning is similar to the way a human brain learns, and it allows ...
- Displaying the list of GameObjects in the form of a tree - Option to add right indent (useful if you use other plugins that add another icons to the hierarchy window) - Any feature can be disabled ...
Test of consistency is critical for the AHP methodology. When a pairwise comparison matrix (PCM) fails the consistency test, the decision maker (DM) needs to make revisions. The state of the art ...