Reading JSON Feed for my Baseball Pool

We have a unique baseball pool here at work.  30 people (for 30 teams) put in $26 (for 26 Weeks in the season) and then each week, you rotate through the 30 MLB teams.  If during the week, the team you have scores exactly 13 runs in a game, you win the weekly pool.

The not fun part for me was reading through all the box scores to see who scored what.  So I found a dependable free score feed from MLB.  But it only returns JSON, so it was time to learn how to work with this feed type and format.

http://gd2.mlb.com/components/game/mlb/year_xx/month_yy/day_zz/master_scoreboard.json

Enter Google Simple JSON package,  org.json.simple

JSONObject jsonObject = (JSONObject) jsonParser.parse(new InputStreamReader(conn.getInputStream()));
JSONObject data = (JSONObject) jsonObject.get("data");
JSONObject games = (JSONObject) data.get("games");
JSONArray game = (JSONArray) games.get("game");

Now that the game data is in the game object, it’s dead nuts simple to rip it to shreds using brute force:

Iterator i = game.iterator();
while (i.hasNext()) {
  JSONObject gameData = (JSONObject) i.next();
  JSONObject linescore = (JSONObject) gameData.get("linescore");
  JSONObject runs = (JSONObject) linescore.get("r");
  String homescore = (String) runs.get("home");
  String awayscore = (String) runs.get("away");
  System.out.println(gameData.get("away_team_name") + " [" + awayscore + "] at " + gameData.get("home_team_name") + " [" + homescore + "]");
  if (Integer.parseInt(homescore) == 13|| Integer.parseInt(awayscore) == 13) {
    scored13 = true;
    System.out.println("*** A Team Scored 13 Runs Last Night ***");
  }
}