Код: Выделить всё
MapЭто данные JSON:
Код: Выделить всё
{
"schoolId": "10928391",
"schoolName": "school A",
"teachers" : [
{
"teacherId": "00001",
"teacherName:": "teacher A",
"subject": "Computer Science",
"lectures": [
{
"id": "CS102",
"name": "Algorithm"
},
{
"id": "CS330",
"name": "Data Communications and Networking"
}
]
},
{
"teacherId": "00002",
"teacherName:": "teacher B",
"subject": "Computer Science",
"lectures": [
{
"id": "CS103",
"name": "Data Structure"
},
{
"id": "CS104",
"name": "Data Structures in C++"
}
]
},
{
"teacherId": "00003",
"teacherName:": "teacher C",
"subject": "Computer Science",
"lectures": [
{
"id": "CS100",
"name": "Introduction to Programming (Java)"
},
{
"id": "CS401",
"name": "Object Oriented Programming"
}
]
}
]
}
Код: Выделить всё
ObjectMapper mapper = new ObjectMapper();
Map schoolInfo = mapper.converValue(restTemplate.exchange(url, HttpMethod.GET, .... ).getBody(), HashMap.class);
Я пытался изменить все элементы внутри лекций
Я пытался изменить все элементы внутри лекций. code> массив.
Например,
Код: Выделить всё
"lectures": [
{
"id": "CS102",
"name": "Algorithm"
},
{
"id": "CS330",
"name": "Data Communications and Networking"
}
]
Код: Выделить всё
"lectures": [
{
"lectureId": "CS102",
"lectureName": "Algorithm",
"lectureRoom": "Room A-1"
},
{
"lectureId": "CS330",
"lectureName": "Data Communications and Networking",
"lectureRoom": "Room A-2"
}
]
Код: Выделить всё
System.out.println(jsonMap.entrySet().stream()
.filter(map -> map.getKey().equals("teachers")).collect(Collectors.toList()).toString());
Подробнее здесь: https://stackoverflow.com/questions/654 ... data-and-m
Мобильная версия