Class CookBookFrame.CookBookJsonReader
java.lang.Object
edu.ntnu.stud.controller.framecontroller.CookBookFrame.CookBookJsonReader
- Enclosing class:
CookBookFrame
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.json.JSONArray
getJsonArray
(String filepath) Reads the JSON file at the given filepath and returns the JSON array containing the recipes.readImageFromJson
(int i, org.json.JSONArray jsonArray) Reads the image of a recipe from the JSON array at the given index.readNameOfRecipe
(int i, org.json.JSONArray jsonArray) Reads the name of a recipe from the JSON array at the given index.
-
Constructor Details
-
CookBookJsonReader
protected CookBookJsonReader()
-
-
Method Details
-
getJsonArray
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
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
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.
-