Package org.lazywizard.lazylib
Class JSONUtils
Object
JSONUtils
Contains methods for dealing with JSON objects.
- Since:
- 1.8
- Author:
- LazyWizard
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classProvides a wrapper aroundJSONObjectthat allows saving and restoring its values to/from the common data folder (saves/common). -
Method Summary
Modifier and TypeMethodDescriptionstatic voidclear(JSONObject toClear) Clears all entries in aJSONObject.loadCommonJSON(String filename) Loads a JSON file from common data, or creates it if it does not already exist.loadCommonJSON(String filename, String defaultJSONPath) Loads a JSON file from common data, or creates it, populates it with default values, and saves it to disk if it does not already exist.static Color
-
Method Details
-
clear
Clears all entries in aJSONObject.- Parameters:
toClear- TheJSONObjectto clear.- Since:
- 2.4
-
toColor
Transform aJSONArrayofints into aColor. Use withSettingsAPI's file loading methods to read a color from a file.- Parameters:
array- TheJSONArrayto convert to aColor.- Returns:
- A
Colorusingarray's color values. - Throws:
JSONException- ifarraydoesn't contain three or moreints- Since:
- 1.8
-
loadCommonJSON
public static JSONUtils.CommonDataJSONObject loadCommonJSON(String filename, @Nullable String defaultJSONPath) throws IOException, JSONException Loads a JSON file from common data, or creates it, populates it with default values, and saves it to disk if it does not already exist.- Parameters:
filename- The filename to load (or create) in common data.defaultJSONPath- The path to a default JSON in a mod folder. Iffilenamedoes not already exist in the common data directory, it will be created and populated with the contents of this JSON file.- Returns:
- A wrapper around a
JSONObjectthat allows saving to common data. - Throws:
IOExceptionJSONException- Since:
- 2.4
-
loadCommonJSON
public static JSONUtils.CommonDataJSONObject loadCommonJSON(String filename) throws IOException, JSONException Loads a JSON file from common data, or creates it if it does not already exist.- Parameters:
filename- The filename to load (or create) in common data.- Returns:
- A wrapper around a
JSONObjectthat allows saving to common data. - Throws:
IOExceptionJSONException- Since:
- 2.4
-