Snippet content copied to clipboard.
Are you sure to delete this snippet? No, don't delete
  1. package com.example;
  2. import java.io.IOException;
  3. import java.net.URL;
  4. import com.fasterxml.jackson.databind.JsonNode;
  5. import com.fasterxml.jackson.databind.ObjectMapper;
  6. public class App {
  7. public static void main(String[] args) {
  8. try {
  9. // Create URL object with API endpoint
  10. URL url = new URL("https://www.calottery.com/api/DrawGameApi/DrawGamePastDrawResults/9/1/20");
  11. // Create ObjectMapper object to parse JSON
  12. ObjectMapper objectMapper = new ObjectMapper();
  13. // Parse JSON from URL into a JsonNode object
  14. JsonNode rootNode = objectMapper.readTree(url);
  15. // Get the "MostRecentDraw" object from the JSON data
  16. JsonNode mostRecentDrawNode = rootNode.get("MostRecentDraw");
  17. // Get the "DrawNumber" value from the "MostRecentDraw" object
  18. int drawNumber = mostRecentDrawNode.get("DrawNumber").asInt();
  19. // Get the "DrawDate" value from the "MostRecentDraw" object
  20. String drawDate = mostRecentDrawNode.get("DrawDate").asText();
  21. // Get the "WinningNumbers" object from the "MostRecentDraw" object
  22. JsonNode winningNumbersNode = mostRecentDrawNode.get("WinningNumbers");
  23. // Get the "1" object from the "WinningNumbers" object
  24. JsonNode numberOneNode = winningNumbersNode.get("1");
  25. // Get the "Number" value from the "1" object
  26. String numberOne = numberOneNode.get("Number").asText();
  27. // Print the results
  28. System.out.println("Draw Number: " + drawNumber);
  29. System.out.println("Draw Date: " + drawDate);
  30. System.out.println("Winning Number 1: " + numberOne);
  31. } catch (IOException e) {
  32. e.printStackTrace();
  33. }
  34. }
  35. }

Edit this Snippet