String解析为json,存储到dto中,然后按照某个字段进行排序

 
 

json解析完成后循环本身是无序的,需要进行处理。

JSONObject parse = (JSONObject) JSON.parse(v2gStInfo.getBase());
for (Map.Entry<String, Object> entry : (parse).entrySet()) {

    V2gBaseDto v2gBaseDto = new V2gBaseDto();
    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm");
    Date parse1 = simpleDateFormat.parse(entry.getKey());
    v2gBaseDto.setObjTime(parse1);

    v2gBaseDto.setObjValue((BigDecimal) entry.getValue());
    v2gBaseDtos.add(v2gBaseDto);
}
v2gBaseDtos = v2gBaseDtos.stream().sorted(Comparator.comparing(V2gBaseDto::getObjTime)).collect(Collectors.toList());
v2gLoadInfoDtos.add(v2gBaseDtos);

猜你喜欢

转载自blog.csdn.net/friggly/article/details/127984940