json与java转换

dojo part:
userInfo.registerOrUpdateUser = function(formID, isNewOrUpdate) {
var isSendNotification = dojo.byId('userReg.sendNotification').checked;
var action = "";
if (isNewOrUpdate == 'new') {
action = "mngrUserActionBean.registerUser";
} else if (isNewOrUpdate == 'update') {
action = "mngrUserActionBean.updateUser";
}

var callback = function(response, xhr){
if(isAjaxSuccess(xhr)){
mtpGrid.refresh('userReg','refresh');
dojo.byId("userReg.cancelBtn").click();
}
};

var params = {};
params.name = dijit.byId('user.name').attr('value');
params.location = dijit.byId('user.location').attr('value');
if (isNewOrUpdate == 'update') {
params.userId = dojo.byId('userReg.userId').value;
}
params.contact = dijit.byId('user.contact').attr('value');
params.email = dijit.byId('user.email').attr('value');
params.notesId = dijit.byId('user.notesId').attr('value');
params.roleList = dojo.toJson(userInfo.getRoleJson());

var url = CENTRAL_CONTROLLER + '?' + PARAM_ACTION + '=' + action;
url += '&isSendNotification='+isSendNotification;
dojoAjaxPost(params, url, null, callback);

}


userInfo.getRoleJson = function() {

var rolesInfoTbl = dojo.byId('mgrRegInfoTbl.rolesInfoTbl');
var rolesInfoTblLen = rolesInfoTbl.rows.length;
var roleList = new Array();
for (var i = 1; i < rolesInfoTblLen; i++) {
var roleObj = {};
var role = rolesInfoTbl.rows[i].cells[3].innerHTML;
roleObj.role = role;
//var divsions = rolesInfoTbl.rows[i].cells[1].innerHTML;
//roleObj.divsions = divsions;
var languages = rolesInfoTbl.rows[i].cells[4].innerHTML;
roleObj.languages = languages;
roleList.push(roleObj);
}

return roleList;
}


java part:

private void setUserRoleInfo(String roleJsonObj) {

if (roleJsonObj == null || roleJsonObj.trim().length() == 0) {
return;
}
JSONArray jsonArray = JSONArray.fromObject( roleJsonObj);
Iterator<JSONObject> iterator = jsonArray.iterator();
List<Role> roleList = new ArrayList<Role>();
while(iterator.hasNext()) {
JSONObject jsonObj = iterator.next();

Role role = new Role();
role.setRoleId((String)jsonObj.get("role"));

// Add current division
List<BusinessUnit> buList = new ArrayList<BusinessUnit>();
buList.add(userSession.getCurrentDiv());
role.setDivisions(buList);

/*String divisions = (String)jsonObj.get("divsions");
String[] buArr = divisions.split(",");
List<BusinessUnit> buList = new ArrayList<BusinessUnit>();
for (String buCode : buArr) {
BusinessUnit bu = new BusinessUnit();
bu.setBU_Code(buCode.replace(GenConst.HTML_AND, GenConst.DB_AND));
buList.add(bu);
}

role.setDivisions(buList);*/

String languages = (String)jsonObj.get("languages");
String[] langArr = languages.split(",");
List<Language> langList = new ArrayList<Language>();
for (String langId : langArr) {
Language lang = new Language();
lang.setLanguageId(langId);
langList.add(lang);
}

role.setLanguages(langList);
roleList.add(role);
}
regUser.setRoles(roleList);
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值