@[TOC]JSONArray的使用
JSONArray的使用
public void setChangeInfo(JSONObject changeInfos1) {
if (changeInfos1 != null) {
List<ExpandCompanyChangeInfo> changeInfos = changeInfos1.getJSONArray("change_infos").stream()
.map(dyDto -> {
return JSON.toJavaObject(((JSONObject) dyDto), ExpandCompanyChangeInfo.class);
}).collect(Collectors.toList());
}
}
public void name() {
List<String> originalNames = new ArrayList<>();
Company mayiCompany = new Company();
JSONObject changeInfos1 = companyFromMayi.setUpOriginalNames(mayiCompany, originalNames);
if (changeInfos1 != null) {
originalNames = changeInfos1.getJSONArray("original_names").stream().map(dyDto -> {
return ((String) dyDto);
}).collect(Collectors.toList());
LOGGER.info("originalNames: " + originalNames);
}
}
public JSONObject setUpOriginalNames(Company mayiCompany, List<String> originalNames) {
List<ChangeInfo> changeInfos = mayiCompany.getChangeInfos();
JSONObject jsonObject = new JSONObject();
if (changeInfos != null && changeInfos.size() > 0) {
for (ChangeInfo info : changeInfos) {
String changeId = getUUIDBefore();
String changeName = info.getName();
String changeBefore = info.getBefore();
String changeAfter = info.getAfter();
// "time": "2016-11-07
if (changeName != null && changeName.equals("名称变更")) {
originalNames.add(changeBefore);
}
}
jsonObject.put("original_names", originalNames);
jsonObject.put("change_infos", infos);
return jsonObject;
}
return null;
}