Tamil Eniyan

Greenhorn
+ Follow
since Sep 14, 2022
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Tamil Eniyan


import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;


public class RWJson
{

@SuppressWarnings("unchecked")
public static void main(String[] args)
{

File parentDir = new File("C://Users//sta2002//Downloads//2022-09-02_81450");

File elements[] = parentDir.listFiles();
for(File element: elements)
{
//System.out.println(element);
File child = new File(element +"//TestResult");
System.out.println(child);

JSONParser jsonParser = new JSONParser();
       
      try(FileReader reader = new FileReader(child +"//statistics.json"))
      {
       
           //Read JSON file
          Object obj = jsonParser.parse(reader);

           JSONArray elementList = (JSONArray) obj;
           System.out.println(elementList);
           
           //Iterate over employee array
           elementList.forEach( emp -> parseEmployeeObject( (JSONObject) emp ) );
      }catch (FileNotFoundException e) {
           e.printStackTrace();
       } catch (IOException e) {
           e.printStackTrace();
       } catch (ParseException e) {
           e.printStackTrace();
       }

}
}



public static void parseEmployeeObject(JSONObject employee)
   {
       //Get employee object within list
       JSONObject employeeObject = (JSONObject) employee.get("Total");
       
       //Get employee first name
       String firstName = (String) employeeObject.get("meanResTime");    
       System.out.println(firstName);
       
       //Get employee last name
       String lastName = (String) employeeObject.get("throughput");  
       System.out.println(lastName);
       
   }

}



I'm also getting the same kind of error.
Can you tell me how to solve this?


2 years ago