转载自:http://blog.csdn.net/java20100406/article/details/6232055
通过配置JsonConfig过滤有可能引起循环的字段,如果不这样,根据hibernate的原则会不断的级联查询.
*************************************Action******************************************************
1.对象。
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.setExcludes( new String[]{ "creator", "module", "testPoints","testProcesses","highLevelRequirements","lowLevelRequirements"} );
String result = JSONObject.fromObject( testCase对象 ,jsonConfig).toString();
2.List数组
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.setExcludes( new String[]{ "creator", "module", "testPoints","testProcesses","highLevelRequirements","lowLevelRequirements"} );
JSONArray lineitemArray = JSONArray.fromObject( testCases集合List ,jsonConfig);
String result = JSONArray.fromObject(lineitemArray).toString();
3.Map对象
Map map = new HashMap();
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.setExcludes( new String[]{ "creator", "module", "testPoints","testProcesses","highLevelRequirements","lowLevelRequirements"} );
JSONArray lineitemArray = JSONArray.fromObject( testCases集合List ,jsonConfig);
map.put("testCases", lineitemArray);
String result = JSONObject.fromObject( map对象 ).toString();
************************************struts.xml*******************************************************
<package name="ajax" extends="json-default" namespace="/ajax">
..........
<action name="childrenAjax" class="**********.AssociationBaseAction" method="getChildren">
<result name="success" type="json">
<param name="root">result</param>
</result>
</action>
..........
</package>
***************************************javascript****************************************************
1.对象。
$.ajax({
type: "POST",
url: "ajax/oneAjax.html",
dataType: "json",
data: "targetId=" + val ,
success: function(result){
var json=eval("("+ result + ")");
$('#selectedResult').append( "<div ;
}
$('#testCaseDiv').append(url);
}
...........................................
}
});