Code Samples
Jump to navigation
Jump to search
JSONArray to List
To convert from a JSONArray (["a","e","i","o","u"]) to a List, you'd use the following:
final JSONArray array = json.getJSONArray("yourKey"); final List<String> asList = new ArrayList<>(array.length()); for (int i = 0; i < array.length(); i++) { asList.add(array.getString(i)); }
List add to JSONArray
To add a List to a JSONArray:
for (String tmp : asList) { array.put(tmp); }
Load JSON file
- Only for your mod, otherwise see Loading extensible JSON file below
- Global.getSettings().loadJSON
- loadJSON() should point to the json file relative to your mod root
Loading extensible JSON file
- Load a JSON that any mod could have added to. Otherwise similar to Load JSON file above
- Global.getSettings().getMergedJSONForMod(example_json, "yourModId")
- Your mod id makes you the master, meaning other mods will overwrite your data instead of the other way around