Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.2 kB
2
Indexable
Never
public static void main(String[] args) {
        try {
            // Read JSON file
            FileReader reader = new FileReader("example.json");

            // Deserialize JSON to Java object
            Gson gson = new Gson();
            ExamData examData = gson.fromJson(reader, ExamData.class);
            System.out.println("Student ID: " + examData.getStudentas().getId());
            System.out.println("Student Name: " + examData.getStudentas().getVardas());
            System.out.println("Student Last Name: " + examData.getStudentas().getPavarde());
            System.out.println("Exam ID: " + examData.getEgzaminas().getId());
            System.out.println("Exam Name: " + examData.getEgzaminas().getPavadinimas());
            System.out.println("Exam Type: " + examData.getEgzaminas().getTipas());
            for (Answer answer : examData.getAtsakymai()) {
                System.out.println("Question: " + answer.getKlausimas());
                System.out.println("Answer: " + answer.getAtsakymas());
            }
            reader.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }