- package com.example;
-
- import java.io.IOException;
- import java.net.URL;
- import com.fasterxml.jackson.databind.JsonNode;
- import com.fasterxml.jackson.databind.ObjectMapper;
-
- public class App {
- public static void main(String[] args) {
- try {
- // Create URL object with API endpoint
- URL url = new URL("https://www.calottery.com/api/DrawGameApi/DrawGamePastDrawResults/9/1/20");
-
- // Create ObjectMapper object to parse JSON
- ObjectMapper objectMapper = new ObjectMapper();
-
- // Parse JSON from URL into a JsonNode object
- JsonNode rootNode = objectMapper.readTree(url);
-
- // Get the "MostRecentDraw" object from the JSON data
- JsonNode mostRecentDrawNode = rootNode.get("MostRecentDraw");
-
- // Get the "DrawNumber" value from the "MostRecentDraw" object
- int drawNumber = mostRecentDrawNode.get("DrawNumber").asInt();
-
- // Get the "DrawDate" value from the "MostRecentDraw" object
- String drawDate = mostRecentDrawNode.get("DrawDate").asText();
-
- // Get the "WinningNumbers" object from the "MostRecentDraw" object
- JsonNode winningNumbersNode = mostRecentDrawNode.get("WinningNumbers");
-
- // Get the "1" object from the "WinningNumbers" object
- JsonNode numberOneNode = winningNumbersNode.get("1");
-
- // Get the "Number" value from the "1" object
- String numberOne = numberOneNode.get("Number").asText();
-
- // Print the results
- System.out.println("Draw Number: " + drawNumber);
- System.out.println("Draw Date: " + drawDate);
- System.out.println("Winning Number 1: " + numberOne);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }