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 ...
随机推荐
- phpcms栏目调用
{loop subcat(0,0,0,$siteid) $r} {php $num++} <h3><a href="{$r[url]}">{$r[catna ...
- inline-block间隔问题
使用inline-block实现一个类似float布局效果,但是inline-block的元素间会存在“4px”的空白间距. span { display: inline-block; width: ...
- Cocos2d-x中Vector使用
1.创建Vector对象 Vector().默认的构造函数. Vector(ssize_t capacity).创建Vector对象,并设置容量. Vector(const Vector<T&g ...
- HDU 1996
Problem Description n个盘子的汉诺塔问题的最少移动次数是2^n-1,即在移动过程中会产生2^n个系列.由于发生错移产生的系列就增加了,这种错误是放错了柱子,并不会把大盘放到小盘上, ...
- bzoj1233: [Usaco2009Open]干草堆tower
Description 奶牛们讨厌黑暗. 为了调整牛棚顶的电灯的亮度,Bessie必须建一座干草堆使得她能够爬上去够到灯泡 .一共有N大包的干草(1<=N<=100000)(从1到N编号) ...
- HashMap通过value反查key
这是今天做了一道字符串的问题,一直MLE,所以想到了减少Map里对应关系数量来降低内存开销.随手谷歌,整理出了如下资料. 如果效率优先的话还是写俩Map吧. import ...
- Unity3D 3D横版跑酷 跳跃
Unity3d 跑酷动画的控制 首先给个图吧, 我们跑酷里面需要动画的,今天说一下动画的知识! 1.导入骨骼动画模型文件之后,如果使用之前版本的unity的播放动画的方式,需要设置AnimationT ...
- c# 集合ArrayList;特殊集合Stack、Queue
一) ArrayList 1.foreach遍历数组中各个元素,执行内部语句 2. 3. 4. myarry.Clear();//将集合清空 bool b = myarry.Contains(3 ...
- AlgorithmsI PA2: Randomized Queues and Deques RandomizedQueue
RandomizedQueue 有几个关键点: 1. 选择合适的数据结构,因为需要任意位置删除元素,Linked list 做不到,必须使用resizing arrays. 2. resizing 的 ...
- 【效率】FIND
文档 HTML Flash CSS 字体 命名颜色 工具 IMG