大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。
Jetbrains全系列IDE使用 1年只要46元 售后保障 童叟无欺
public static void main(String[] args) throws IllegalAccessException, InvocationTargetException {
String str = "[{\"repaymentTime\":\"2019-05-15 10:40:00\",\"repaymentMoney\":\"840\",\"consumption\":[{\"consumptionTime\":\"2019-05-12 15:20:00\",\"consumptionMoney\":\"430\"},{\"consumptionTime\":\"2019-05-13 10:05:00\",\"consumptionMoney\":\"410\"}]"
+ "}, {\"repaymentTime\":\"2019-05-20 10:40:00\",\"repaymentMoney\":\"300\",\"consumption\":[{\"consumptionTime\":\"2019-05-16 11:02:00\",\"consumptionMoney\":\"120\"},{\"consumptionTime\":\"2019-05-18 13:00:00\",\"consumptionMoney\":\"180\"}]}]";
List<Map> list = JSONArray.fromObject(str);
System.out.println(list);
for (Map map: list) {
// map转entity
PlanDTO dto = JSON.parseObject(JSON.toJSONString(map), PlanDTO.class);
System.out.println(dto.getRepaymentTime());
System.out.println(dto.getRepaymentMoney());
JSONArray consumptionArray = (JSONArray)map.get("consumption");
List<Consumption> consumptionList = (List<Consumption>) consumptionArray.toCollection(consumptionArray, Consumption.class);
for (Consumption consumption: consumptionList) {
System.out.println(consumption.getConsumptionTime());
System.out.println(consumption.getConsumptionMoney());
}
}
}
PlanDTO.java
public class PlanDTO {
private String repaymentTime; // 时间
private String repaymentMoney; // 金额
List<Consumption> consumption = new ArrayList<Consumption>(); // 消费
public String getRepaymentTime() {
return repaymentTime;
}
public void setRepaymentTime(String repaymentTime) {
this.repaymentTime = repaymentTime;
}
public String getRepaymentMoney() {
return repaymentMoney;
}
public void setRepaymentMoney(String repaymentMoney) {
this.repaymentMoney = repaymentMoney;
}
public List<Consumption> getConsumption() {
return consumption;
}
public void setConsumption(List<Consumption> consumption) {
this.consumption = consumption;
}
}
Consumption.java
public class Consumption {
private String consumptionTime; // 时间
private String consumptionMoney; // 金额
public String getConsumptionTime() {
return consumptionTime;
}
public void setConsumptionTime(String consumptionTime) {
this.consumptionTime = consumptionTime;
}
public String getConsumptionMoney() {
return consumptionMoney;
}
public void setConsumptionMoney(String consumptionMoney) {
this.consumptionMoney = consumptionMoney;
}
}
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/195939.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...