Skip to content

Commit ef98115

Browse files
author
Benjamin Yap
committed
Add method to load internal JSON files
1 parent d966f37 commit ef98115

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/com/bwyap/utility/resource/ResourceLoader.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,29 @@ public static JSONObject loadJSON(File file) {
5555
}
5656

5757

58+
/**
59+
* Loads a JSON object from an internal file.
60+
* @param path the internal path of the JSON file
61+
* @return
62+
*/
63+
public static JSONObject loadInternalJSON(String path) {
64+
JSONObject jsonObject = null;
65+
66+
JSONParser parser = new JSONParser();
67+
try {
68+
String config = loadInternalTextFileAsString(path);
69+
Object o = parser.parse(config);
70+
jsonObject = (JSONObject) o;
71+
}
72+
catch (ParseException e) {
73+
log("An error occurred while trying to parse internal JSON file <" + path + ">.");
74+
printStackTrace(e);
75+
}
76+
77+
return jsonObject;
78+
}
79+
80+
5881
/**
5982
* Reads an internal CSV file from within the jar and loads the data into a hash map.
6083
* @param path

0 commit comments

Comments
 (0)