Entfernen Sie doppelte Objekte von JSON Array in Java oder KotlinJava

Java-Forum
Anonymous
 Entfernen Sie doppelte Objekte von JSON Array in Java oder Kotlin

Post by Anonymous »

Ich versuche herauszufinden, wie man doppelte Klasseninformation aus schulinformation entfernen, wenn die folgenden Bedingungen übereinstimmen:
  • Code: Select all

    classInformation.teacherPercentage
    und classInformation.teachInfo.id sind gleich
  • Code: Select all

    classInformation.studentPercentage
    and classInformation.studentInfo.id, classInformation.studentInfo.style, classInformation.studentInfo.graduationYear are the same
JSON:

Code: Select all

{
"schoolInfomration": [
{
"classInformation": [
{
"studentPercentage": 50,
"studentInfo": {
"id": 4,
"style": 3,
"graduationYear": 2028
}
},
{
"teacherPercentage": 50,
"teacherInfo": {
"id": "10019",
"name" : "test2"
}
}
]
},
{
"classInformation": [
{
"studentPercentage": 50,
"studentInfo": {
"id": 4,
"style": 3,
"graduationYear": 2028
}
},
{
"teacherPercentage": 50,
"teacherInfo": {
"id": "10019",
"name" : "test1"
}
}
]
},
{
"classInformation": [
{
"studentPercentage": 50,
"studentInfo": {
"id": 4,
"style": 3,
"graduationYear": 2023
}
},
{
"teacherPercentage": 50,
"teacherInfo": {
"id": "10018",
"name": "test3"
}
}
]
}
]
}
< /code>
Ausgabe: < /p>
{
"schoolInfomration": [
{
"classInformation": [
{
"studentPercentage": 50,
"studentInfo": {
"id": 4,
"style": 3,
"graduationYear": 2028
}
},
{
"teacherPercentage": 50,
"teacherInfo": {
"id": "10019",
"name" : "test2"
}
}
]
},
{
"classInformation": [
{
"studentPercentage": 50,
"studentInfo": {
"id": 4,
"style": 3,
"graduationYear": 2023
}
},
{
"teacherPercentage": 50,
"teacherInfo": {
"id": "10018",
"name": "test3"
}
}
]
}
]
}
< /code>
Datenklassen: < /p>

data class Root(
val schoolInfomration: List,
)

data class SchoolInfomration(
val classInformation: List,
)

data class ClassInformation(
val studentPercentage: Long?,
val studentInfo: StudentInfo?,
val teacherPercentage: Long?,
val teacherInfo: TeacherInfo?,
)

data class StudentInfo(
val id: Long,
val style: Long,
val graduationYear: Long,
)

data class TeacherInfo(
val id: String,
val name: String,
)

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post