Class CookBookFrame.CookBookJsonReader

java.lang.Object
edu.ntnu.stud.controller.framecontroller.CookBookFrame.CookBookJsonReader
Enclosing class:
CookBookFrame

protected static class CookBookFrame.CookBookJsonReader extends Object
Nested class to read the JSON file containing the recipes. The class reads the JSON file and returns the JSON array containing the recipes. The class also reads the image and name of a recipe at a given index.
  • Constructor Details

    • CookBookJsonReader

      protected CookBookJsonReader()
  • Method Details

    • getJsonArray

      public org.json.JSONArray getJsonArray(String filepath) throws FileNotFoundException
      Reads the JSON file at the given filepath and returns the JSON array containing the recipes. If the file is not found, a FileNotFoundException is thrown.
      Parameters:
      filepath - The path to the JSON file containing the recipes.
      Returns:
      The JSON array containing the recipes.
      Throws:
      FileNotFoundException - If the file is not found.
    • readImageFromJson

      public String readImageFromJson(int i, org.json.JSONArray jsonArray)
      Reads the image of a recipe from the JSON array at the given index.
      Parameters:
      i - The index of the recipe in the JSON array.
      jsonArray - The JSON array containing the recipes.
      Returns:
      The image of the recipe at the given index.
    • readNameOfRecipe

      public String readNameOfRecipe(int i, org.json.JSONArray jsonArray)
      Reads the name of a recipe from the JSON array at the given index.
      Parameters:
      i - The index of the recipe in the JSON array.
      jsonArray - The JSON array containing the recipes.
      Returns:
      The name of the recipe at the given index.