I have this json file:
{
"Update tree": {
"average time": 0.01610115085649609,
"best time": 0.003310859220941582,
"count": 651,
"success rate": 100,
"worst time": 0.621779361692829
},
"Update renderables": {
"average time": 0.1988377572034353,
"best time": 0.0003510859220941582,
"count": 649,
"success rate": 100,
"worst time": 12.8709652214104
},
"Before render": {
"average time": 0.5206290903024032,
"best time": 0.01522995241633128,
"count": 188,
"success rate": 100,
"worst time": 81.06473259514415
},
"Rendering": {
"average time": 4.425231035278629,
"best time": 0.4979532268296139,
"count": 214,
"success rate": 100,
"worst time": 71.34537426614806
},
"After render": {
"average time": 0.06479598048728916,
"best time": 0.0301288189105684,
"count": 563,
"success rate": 100,
"worst time": 0.6413134310963844
}
}
where I want to calculate the average of all avergaes in each json object how do I iterate through the json objects?
I am trying to get all avergaes values sum them up and calculate their average
EDIT:
I have this for loop which I want to iterate through each object (and not getting its member name but to actually iterate through the objects and get the values and then sum them up):
for(int i=0; i<json.size(); i++){
sumAllAverages(json.getAsJsonObject());
}
private static void sumAllAverages(JsonObject asJsonObject) {
sum += Float.parseFloat(asJsonObject.get("average time").toString());
}