json-lib 中
一:
JSONObject:实现JavaBean和json对象之间的相互转换,基本用法有:
1.JSONObject jObject=JSONObject.fromObject(javaBean);将javaBean转换为json对象
2.Object javaBean=JSONObject.toBean(jsonObject);将json对象转换成javaBean
例子:
FbcmCeditApp app =getDaoFacade().getFbcmCeditAuditDao().getFbcmCeditAppByCltno(cltno);
String[] a ={"fbcmAppDetails","fbcmCrtappDetails","fbcmFacilityUses"}; // 为app对象中的set集合名称
String sq = JSONObject.fromObject(app,JsonUtil.configJson(a,"yyyy-MM-dd")).toString();// 把java对象
转化为JSON对象,
二:
集合
JsonArray:实现java集合与json对象之间的相互转换,基本用法如下
1.JSONOArray jArray=JSONArray.fromObject(java集合);将java集合转为json对像
2.Object array=JSONArray.toArray(jsonArray);将json对象数组转换为java数组
3.Object array=JSONArray.toList(jsonArray);将json对象转换成List
例子:
FbcmAppDetail tempDetail = getDaoFacade().getFbcmCeditAuditDao().findSqsm(app.getOldid());
if(tempDetail!=null && String.valueOf(tempDetail.getType()).equals((String.valueOf
(Statics.CRETYPE_CHG))) && "调整说明".equals(tempDetail.getKeyname())){
String[] a ={"fbcmCeditApp","type","keyname","disorder"};
tzsm = JSONObject.fromObject(tempDetail,JsonUtil.configJson(a)).toString();
}
三:
后台返回数据包装成JSON数据
public String doFbcmcEditApp(String cltno){
StringBuffer s = new StringBuffer();
s.append("{'sq':").append(sq).append(",'crerate':'").append(crerate).append("','tzxishu':'").append
(yssx.getLoadadjrate()).append("','tzsm':").append(tzsm).append(",'sqmx':").append(sqmx).append
(",'tzql':").append(tzsq).append(",'tzmx':").append(tzmx).append("}");
return s.toString();
}
四:
如果返回值有bean 在 dwr。xml中进行 java对象 和 javascript对象之间的转化
<convert match="com.nstc.fbth.model.base.FbcmCrtappDetail" converter="bean">
<param name="include" value="id,type,warttype,wartcmt,amt,usedamt" />
</convert>
五:
用到spring中的对象
<create creator="spring" javascript="cedit">
<param name="beanName" value="ceditAuditServer" />
<include method="doFbcmcEditApp"/>
<include method="doFbcmcEditAppById"/>
<include method="saveFbcmcEditApp"/>
</create>
六:bean
web。xml中的配置
<servlet>
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>