json遍历,List>遍历

时间:2022-03-04 10:32:25

js怎样给input对象追加属性,如disabled

$(":textbox").attr({"disabled":true});

 

List<Map<String,Object>>遍历:

List<Map<String,Object>> strLists = new ArrayList<Map<String,Object>>();

if(strLists!=null){
if(strLists.size()>0){
for(Map<String,Object> m:strLists){
for(String k:m.keySet()){
if(m.get(k)!=null){
strLists1.add(m.get(k).toString());
}
}
}
}
}

json遍历:

收集表单参数:

jQuery.prototype.serializeObject=function(){
var obj=new Object();
$.each(this.serializeArray(),function(index,param){
if(!(param.name in obj)){
obj[param.name]=param.value;
}
});
return obj;
};

 

 

function saveBtn(){
var dataE = $("#dataForm").serializeObject();
var id=$("#dataId").val();
alert(JSON.stringify(dataE));
alert(id);
$.ajax({
url: "/settings/insertData",
type : 'POST',
data :{"str":JSON.stringify(dataE),"id":id},
timeout : 20000,
error:function(data){

},
success:function(data){
alert("添加成功");
$("#myModal2").modal('toggle')
window.location.reload();
}
});
}

@RequestMapping(value="insertData")
@ResponseBody
public Map<String,Object> insertData(HttpServletRequest request,
HttpServletResponse response,Integer id,String str) throws Exception{
String key=null;
String value;
String tableName=null;
BusinessDesc businessDesc = businessDescService.queryById(id);
//取出所有字段
List<ColumnRule> columnnlist = columnRuleService.findByBusinessId(id);
List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
List<String> list2 = new ArrayList<String>();
Map<String,Object> maps=new HashMap<String,Object>();
JSONObject jsonObject = new JSONObject(str);
Iterator iterator = jsonObject.keys();
while(iterator.hasNext()){
Map<String,Object> map=new HashMap<String,Object>();
key = (String) iterator.next();
value = jsonObject.getString(key);
for(ColumnRule rule:columnnlist){
if(rule.getName().equals(key)){
if(rule.getFieldType().contains("int")){
if(value!=null && !"".equals(value)){
map.put("value", Integer.parseInt(value));
}else{
map.put("value",0);
}
}else{
map.put("value", value);
}
}
}
map.put("key", key);
list.add(map);
}
if(businessDesc!=null){
tableName=businessDesc.getTablename();
}

maps.put("list", list);
maps.put("table", tableName);
businessDescService.insertData(maps);
return maps;
}

 

 

 

 

Java遍历JSON

JSONObject jsonObject = new JSONObject(s);
然后用Iterator迭代器遍历取值,建议用反射机制解析到封装好的对象中

JSONObject jsonObject = new JSONObject(jsonString);
Iterator iterator = jsonObject.keys();
while(iterator.hasNext()){
key = (String) iterator.next();
value = jsonObject.getString(key);
}

转自:http://www.cnblogs.com/GarfieldTom/p/5100918.html