I have the json object in the following format.
[
{
"StudentID": 1,
"StudentMarks": [
{
"StudentID": 1,
"English": 1500000,
"Maths": 15,
"Science": 15,
"History": 10,
"TestID": 1,
"Date": "2018-01-29T14:38:11.01"
},
{
"StudentID": 1,
"English": 155,
"Maths": 1578,
"Science": 15,
"History": 10,
"TestID": 2,
"Date": "2018-01-29T14:38:11.01"
},
{
"StudentID": 1,
"English": 155,
"Maths": 15,
"Science": 150,
"History": 10,
"TestID": 3,
"Date": "2018-01-29T14:38:11.01"
},
{
"StudentID": 1,
"English": 150,
"Maths": 15,
"Science": 15,
"History": 10,
"TestID": 6,
"Date": "2018-01-29T14:38:11.01"
},
{
"StudentID": 1,
"English": 155,
"Maths": 1578,
"Science": 15,
"History": 10,
"TestID": 7,
"Date": "2018-01-29T14:38:11.01"
}
]
},
{
"StudentID": 2,
"StudentMarks": [
{
"StudentID": 2,
"English": 155,
"Maths": 151,
"Science": 15,
"History": 1025,
"TestID": 4,
"Date": "2018-01-29T14:38:11.01"
},
{
"StudentID": 2,
"English": 1551,
"Maths": 15,
"Science": 15,
"History": 100,
"TestID": 5,
"Date": "2018-01-29T14:38:11.01"
},
{
"StudentID": 2,
"English": 1,
"Maths": 1,
"Science": 15,
"History": 10,
"TestID": 8,
"Date": "2018-01-29T14:38:11.01"
}
]
}
]
In this i need to list the student id and also the latest test marks in an android custom listview,
To extract each student id, i am using
JSONArray myListsAll= new JSONArray(jsonStr);
for(int i=0;i<myListsAll.length();i++)
{
JSONObject c= (JSONObject) myListsAll.get(i);
History= c.getString("History");
Science= c.getString("Science");
Maths= c.getString("Maths");
English= c.getString("English");
}
But I want the student id and marks details of the latest test. which i thought of getting array element from 'StudentMarks' for which 'TestId' is maximum. How to do that?