list对象转json

for (LdInquiryPage ldInquiryPage : l) {
List<LdInquiryCostEntity> lson = jdbcTemplate.query(sqlson+ldInquiryPage.getId()+"'", rowMapperson);
ldInquiryPage.setLdInquiryCostList(lson);
ldInquiryPage.setInContent(sdf.format(ldInquiryPage.getCreateDate()));
}

 

1、LIST对象转json字符串
net.sf.json.JSONArray jsonarray = net.sf.json.JSONArray.fromObject(l);
js.put("content", jsonarray.toString());

 

2、jsonArray取值

JSONArray json

for (int i = 0; i < json.size(); i++) {
JSONObject jsonObject=(JSONObject) json.get(i);

String sql = "UPDATE ld_inquiry SET updatestate='0' WHERE id='"+jsonObject.get("id")+"' AND updatestate='"+jsonObject.get("updatestate")+"'";
// String sql="update ldc_handbook_order set hbo_upstate='0' where hbo_orderno='"+jsonObject.get("ordercode")+"' and hbo_upstate='"+jsonObject.get("updatestate")+"'";
jdbcTemplate.update(sql);
}

 

3、json字符串转list对象

List<CommonContractEntity> contractList = (List<CommonContractEntity>)net.sf.json.JSONArray.toList(array, CommonContractEntity.class);

上一篇:LINUX篇,设置MYSQL远程访问实用版


下一篇:用户号已经存在是否覆盖解决办