public String getMatchesJSON(List<Match> matches) { JSONArray array = new JSONArray(); try { for (Match match : matches) { JSONObject object = new JSONObject(); object.put("id", match.getMatchId()); object.put("t1", match.getTeamOne()); object.put("t2", match.getTeamTwo()); array.put(object); } } catch (JSONException e) { logger.severe(e.getMessage()); } return array.toString(); }
public String getSimpleScoresJSON(List<SimpleScore> simpleScores, long timestamp) { JSONArray array = new JSONArray(); try { for (SimpleScore simpleScore : simpleScores) { JSONObject scoreObject = new JSONObject(); scoreObject.put("id", simpleScore.getId()); scoreObject.put("si", simpleScore.getSimple()); scoreObject.put("de", simpleScore.getDetail()); array.put(scoreObject); } } catch (JSONException e) { logger.severe(e.getMessage()); } return array.toString(); }
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { List<Entity> ents = MemberDAO.getAll(); // DatastoreService ds = DatastoreServiceFactory.getDatastoreService(); // Query q = new Query("Member").addSort("name", SortDirection.DESCENDING); // List<Entity> ents = ds.prepare(q).asList( // FetchOptions.Builder.withLimit(10)); try { JSONArray aryJson = Util.MembersToJsonArray(ents); Util.sendUTF8JSON(aryJson.toString(), resp); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); Util.sendErrorJson(e.getLocalizedMessage(), resp); } }