一周有7天,每天有12个时间段
[{"time":[{"endHour":"02","startHour":"00"},{"endHour":"04","startHour":"02"},{"endHour":"06","startHour":"04"},{"endHour":"08","startHour":"06"},{"endHour":"10","startHour":"08"},{"endHour":"12","startHour":"10"},{"endHour":"14","startHour":"12"},{"endHour":"16","startHour":"14"},{"endHour":"18","startHour":"16"},{"endHour":"20","startHour":"18"},{"endHour":"22","startHour":"20"},{"endHour":"24","startHour":"22"}],"week":1},{"time":[{"endHour":"02","startHour":"00"},{"endHour":"14","startHour":"12"},{"endHour":"24","startHour":"22"}],"week":2},{"time":[{"endHour":"02","startHour":"00"},{"endHour":"14","startHour":"12"},{"endHour":"24","startHour":"22"}],"week":3},{"time":[{"endHour":"02","startHour":"00"},{"endHour":"04","startHour":"02"},{"endHour":"06","startHour":"04"},{"endHour":"08","startHour":"06"},{"endHour":"10","startHour":"08"},{"endHour":"12","startHour":"10"},{"endHour":"14","startHour":"12"},{"endHour":"16","startHour":"14"},{"endHour":"18","startHour":"16"},{"endHour":"20","startHour":"18"},{"endHour":"22","startHour":"20"},{"endHour":"24","startHour":"22"}],"week":4},{"time":[{"endHour":"02","startHour":"00"},{"endHour":"14","startHour":"12"},{"endHour":"24","startHour":"22"}],"week":5},{"time":[{"endHour":"02","startHour":"00"},{"endHour":"14","startHour":"12"},{"endHour":"24","startHour":"22"}],"week":6},{"time":[{"endHour":"02","startHour":"00"},{"endHour":"04","startHour":"02"},{"endHour":"06","startHour":"04"},{"endHour":"08","startHour":"06"},{"endHour":"10","startHour":"08"},{"endHour":"12","startHour":"10"},{"endHour":"14","startHour":"12"},{"endHour":"16","startHour":"14"},{"endHour":"18","startHour":"16"},{"endHour":"20","startHour":"18"},{"endHour":"22","startHour":"20"},{"endHour":"24","startHour":"22"}],"week":7}]
public List<ValidPeriodDto> getValidPeriodDtoList() {
List<ValidPeriodDto> list = new ArrayList<>(); if (StringUtils.isNotBlank(validPeriod)) { JSONArray obj = JSON.parseArray(validPeriod); for (int i = 0; i < obj.size(); i++) { JSONObject job = obj.getJSONObject(i); int week = job.getIntValue("week"); JSONArray temp = JSON.parseArray(job.get("time").toString()); for (int j = 0; j < temp.size(); j++) { JSONObject t = temp.getJSONObject(j); String hourBegin = t.getString("startHour"); String hourEnd = t.getString("endHour"); list.add(new ValidPeriodDto(week, hourBegin, hourEnd)); } } } return list;}
import com.alibaba.fastjson.JSONObject;
json转java对象
AdvertOrderJsonDO adj = JSONObject.parseObject(advertOrderDO.getJson(),AdvertOrderJsonDO.class);
java对象转json
JSON.toJSONString(advertOrderJsonDO)