I have this JSON:
{
"Details":{
"Customer Input": "Type Here",
"Input Status": 0,
"CumulativeValues":[
{
"LinkToPost" : "www.google.com"
},
{
"ScoreMin" : "0"
},
{
"ScoreMax" : "100"
}
]
}
}
I have deserialized to get "Details" like below:
Map<String, Object> detailsMap = (Map<String, Object>)JSON.deserializeUntyped(resp.getBody());
Map<String, Object> detailDataMap = (Map<String, Object>)detailsMap.get('Details');
List<Object> cumulativeValuesList = (List<Object>) detailDataMap.get('CumulativeValues');
Now, I am trying to fetch the "ScoreMin" and "ScoreMax" values like below:
Map<String, Object> getScoreMin = (Map<String, Object>) cumulativeValuesList[1];
Map<String, Object> getMaxScore = (Map<String, Object>) cumulativeValuesList[2];
Although it works to fetch the ScoreMin and ScoreMax values here, I would like to do it without fetching on basis of Indexes like [1]
, [2]
.
I tried with Iterating cumulativeValuesList
checking if it Contains "ScoreMin" and "ScoreMax", but the results were Null.
for(Object obj : cumulativeValuesList){
if(cumulativeValuesList.contains('ScoreMin')){
Map<String,Object> minimumScoreMap = (Map<String, Object>) obj;
}
if(cumulativeValuesList.contains('ScoreMax')){
Map<String,Object> maximumScoreMap = (Map<String, Object>) obj;
}
}
Kindly suggest me how to get the values of ScoreMin and ScoreMax please.
Thank you.