【发布时间】:2021-10-04 08:10:43
【问题描述】:
我有一个来自此表单的 json 响应。
"calendarList": [
{
"id": "1",
"event": {
"id": "11",
"name": "Track the working hours",
"color": "blue",
"place": "office",
}
},
{
"id": "2",
"event": {
"id": "12",
"name": "Finish DTOs",
"color": "blue",
"place": "office",
}
}
]
如何访问位置值?对于列表中的所有 dto 对象,位置值将是相同的,即 OFFICE,因此我只需要以某种方式访问位置值之一。 CalendarDto 列表包含多个 EventDto 对象,具有 id、name、color 和 place 属性。
final List<CalendarDto> calendarList = calendarService.getCalendars(startDate, endDate);
EventDto eventDto = new EventDto();
EventSender sender = new EventSender ("EVENTS");
sender.withData("place", calendarList.stream() -> this is where I tried to get the value, but it didn't work
.findFirst(eventDto.getPlace()));
【问题讨论】:
-
您好,这取决于您使用的框架。正如你所说的它是一个数组,所以它就像 data[0].event.place 或 data.stream().map(DTO::getPlace) 然后收集到地点列表或你想要的东西
-
calendarList.get(0).getEvent().getPlace()?如果您的日历列表映射正确..