入参格式:
{
"TYPE":"1",
"ID":"123456",
"NAME":"张三",
"SPELLNAME":"zhangsan",
"MAIL":"zhangsan@126.com",
"USERTYPE":"0",
"TELEPHONE":"2207",
"ADDRESS":"西楼201",
"LOGNAME":"bgt_zhangsan",
"MJ":"1",
"STATE":"1",
"FAX":"123456",
"NICK":"zs",
"POSITION":"处员",
"UUID":"c066-96cf-4ad3-a917-0d66",
"CODE":"rctb_123456",
"MOBILE":"1341111131",
"BIRTHYEAR":"1980",
"BIRTHMONTH":"1",
"NATION":"汉族",
"POLITICAL":"群众",
"EDUCATION":"本科",
"DEGREE":"学士",
"LEVEL":"0",
"SEX":"1",
"ORGANIZEIDS":[{"ID":"123","ISMAIN":"1","INDEX":"1","MAINUNIT":"123","UUID":" c066-96cf-4ad3-a917-0d69","CODE":"10000001803"}] (数组里面包含的是对象)
}
1.json.getJSONArray方法直接获取到json数组,JSONObject jsonObj = arr.getJSONObject(i);遍历数组, System.out.println(code1);
JSONArray arr = json.getJSONArray("ORGANIZEIDS"); for (int i = 0; i < arr.size(); i++) { JSONObject jsonObj = arr.getJSONObject(i); String code1 = jsonObj.getString("CODE"); System.out.println(code1); }
2.log.info的使用
必选在对应的类上打上注解@Slf4j,log.info("前端的入参:"+json.toString());使用结束
3.json数组转换为java集合
Object str = json.get("ORGANIZEIDS"); String s = JSON.toJSONString(str); log.info("转换单位数组为字符串:"+s); List<Organizeids> list = JSON.parseArray(s, Organizeids.class);
4.遍历集合中的局部变量,复制给全局变量
String depCode="";现在外部定义一个全局变量 for (Organizeids organizeids : list) { if ("1".equals(organizeids.getISMAIN())) { String code1 = organizeids.getCODE(); depCode=code1;赋值给全局变量 } }
5.MP增加保存对象
if(exitTpuser==null) {
Tpuser tpuser = new Tpuser();必须先new一个
tpuser.setPuserid(UUID.randomUUID().toString());
tpuser.setEmail(email);
tpuser.setPhone(mobile);
tpuser.setMobiletel(mobile);
tpuser.setName(name);
tpuser.setDepartmentid(b01.getB00());
tpuser.setUsername(email);
String enPwd = getBDPEncryptStrategyService().encrypt(defaultPassword);
tpuser.setPassword(enPwd);
tpuserService.save(tpuser);
return new JsonSuccessObject<>(0, "人员数据同步成功");
}