package de.jeyp91.teamidmatcher; import de.jeyp91.apifootball.APIFootballConnector; import org.json.simple.JSONArray; import org.json.simple.JSONObject; public class TeamIDMatcherTemplateCreator { APIFootballConnector con; JSONArray teams; public TeamIDMatcherTemplateCreator(int season, int league) throws Exception { this.con = APIFootballConnector.getAPIFootballConnectorInstance(season); JSONObject apiObject = con.getTeamsForLeague(season, league); JSONObject teamsObject = (JSONObject) apiObject.get("api"); this.teams = (JSONArray) teamsObject.get("teams"); } public String getTeamsTemplate() { String teamsTemplate = ""; for (Object team : this.teams) { JSONObject teamObject = (JSONObject) team; teamsTemplate += ",\n"; teamsTemplate += " {\n"; teamsTemplate += " \"teamname\": \"" + teamObject.get("name") + "\",\n"; teamsTemplate += " \"tippligaID\": " + ",\n"; teamsTemplate += " \"apiFootballID\": " + teamObject.get("team_id") + "\n"; teamsTemplate += " }"; } return teamsTemplate; } }