JSON 遍历转为Model Bean
@RequestMapping(value = "/batchAddPageIndexBrand")
@ResponseBody
public HashMap<String, Object> batchAddPageIndexBrand(HttpServletRequest request,HttpServletResponse response){
String userId = request.getSession().getAttribute("userId").toString();
HashMap<String, Object> mapRes = new HashMap<String, Object>();
List<PageIndexBrand> pageIndexBrandList=new ArrayList<PageIndexBrand>();
String jsonStr=request.getParameter("json");
if(StringUtils.isEmpty(jsonStr)){
mapRes.put("code", -1);
mapRes.put("msg","没有要操作的数据");
return mapRes;
}
//将JSON字符串转为JSON数组
JSONArray json= JSONArray.fromObject(jsonStr);
if(json==null || json.size()==0){
mapRes.put("code", -1);
mapRes.put("msg","没有要操作的数据");
return mapRes;
}
//遍历JSON数组
for(int i=0;i<json.size();i++){
//获取JSON对象
JSONObject object = (JSONObject)json.get(i);
//将JSON对象转为ModelBean
PageIndexBrand pageIndexBrand = (PageIndexBrand)JSONObject.toBean(object,PageIndexBrand.class);
if(pageIndexBrand != null){
pageIndexBrand.setAddUserId(Integer.parseInt(userId));
pageIndexBrand.setAddTime(StringUtil.returnDateFormat(new Date(),"yyyy-MM-dd HH:mm:ss"));
pageIndexBrand.setEditTime(StringUtil.returnDateFormat(new Date(),"yyyy-MM-dd HH:mm:ss"));
pageIndexBrand.setEditUserId(Integer.parseInt(userId));
pageIndexBrandList.add(pageIndexBrand);
}
}
ServiceMessage<?> res=pageIndexBrandService.batchOperateIndexBrand(pageIndexBrandList);
if(res.getStatus().getCode().equals("0")){
mapRes.put("code", 0);
mapRes.put("msg", "ok");
}else{
mapRes.put("code", -1);
mapRes.put("msg",res.getMessage());
}
return mapRes;
}
JSON 遍历转为Model Bean的更多相关文章
- Json对象转为实体对象
Json对象转为实体对象 1.Bean中申明 trainTypeList: public class TrainTypeQueryParam implements Serializable { pri ...
- php json字符串转为数组或对象
从网上查到的方法是 用get_object_vars 把类类型转换成数组 然后在用foreach 遍历即可 $array = get_object_vars($test); $json= '[{&q ...
- json对象转为字符串,当做参数传递时加密解密
[son对象 字符串 互相转行] 比如我有两个变量,我要将a转换成字符串,将b转换成JSON对象: var a={"name":"tom","sex ...
- SpringMVC中出现" 400 Bad Request "错误(用@ResponseBody处理ajax传过来的json数据转成bean)的解决方法
最近angularjs post到后台 400一头雾水 没有任何错误. 最后发现好文,感谢作者 SpringMVC中出现" 400 Bad Request "错误(用@Respon ...
- DataTable转json字符串,jQuery.parseJSON()把json字符串转为标准的json对象格式
1.string res = DataTableToJson.DataTable2Json(dt);讲DataTable转换为json字符串 http://www.365mini.com/page/j ...
- 小程序json字符串转为对象
小程序里json字符串转为对象使用JSON.parse()方法转变无效, 看报错提示有单引号“ ' ” 因为单引号而无效, 将单引号全改双引号即可. 报错如下: VM11050:1 thirdScri ...
- json遍历 分别使用【原】
json遍历 一 使用org.json.JSONObject遍历 之后的所有遍历都参考了:http://blog.csdn.net/u010648555/article/details/4981538 ...
- 将JSON字典转换为Model文件
将JSON字典转换为Model文件 1. 一切尽在不言中 2. 源码 https://github.com/YouXianMing/CreateModelFromJson 3. 说明 如果你还在手动写 ...
- 第61天:json遍历和封装运动框架(多个属性)
一.json 遍历 for in 关键字 for ( 变量 in 对象) { 执行语句; } 例如: var json = {width:200,height:300,left:50}co ...
随机推荐
- UFLDL实验报告1: Softmax Regression
PS:这些是今年4月份,跟斯坦福UFLDL教程时的实验报告,当时就应该好好整理的…留到现在好凌乱了 Softmax Regression实验报告 1.Softmax Regression实验描述 So ...
- 优化MYSQL FILESORT
用Explain分析SQL语句的时候,经常发现有的语句在Extra列会出现Using filesort,根据mysql官方文档对他的描述: 引用 MySQL must do an extra pass ...
- Windows环境下安装PHPUnit
Windows环境下安装PHPUnit,在此整理一下,以便大家参考. 本人测试安装环境:Windows7(win32) + Apache(2.2.13) + PHP(5.3.6) 1. 以管理员 ...
- 构造函数语义学之Default Constructor构建操作
一.Default Constructor的构建操作 首先大家要走出两个误区: 1).任何class如果没有定义default constructor,就会被合成一个来. 2).便以其合成出来的def ...
- Light OJ 1011 - Marriage Ceremonies(状压DP)
题目大意: 有N个男人,和N个女人要互相匹配,每个男人和每个女人有个匹配值. 并且匹配只能是1对1的. 问所有人都匹配完成,最大的匹配值是多少? 状压DP,暴力枚举就OK了, 这个题目略坑,因为他 ...
- 控件treeview使用
一:实现功能,获得选中节点,在选中节点下添加节点,折叠,展开,删除,得到选中节点下checked项,选中根节点其下节点也选中,图标.上图 二:相关代码 using System; using Syst ...
- Mac下Shell快捷键
ctrl+a //移到行首 ctrl+e //移到行尾 ctrl+y // 插入最近删除的单词或语句 ctrl+k //删除光标处到行尾部分 ctrl+u //删除光标处到行首部分 ctrl+w // ...
- datagridview bindingsource
调用bindindsource的ResetBindings() 方法
- CodeForces 592B
题目链接: http://codeforces.com/problemset/problem/592/B 这个题目没啥说的,画图找规律吧,哈哈哈 程序代码: #include <cstdio&g ...
- 暴力求解——UVA 572(简单的dfs)
Description The GeoSurvComp geologic survey company is responsible for detecting underground oil dep ...