Re: [Jtimer-devel] [Jtimer-commits] 01/04: corrected method for getting times that was ignoring the date parameters and always sending all the times of a task
Le 19/05/2016 09:23, chorem.org scm a écrit :
- String resultingJSON = "{\"uuid\":\"" + task.getName()+ "\",\"periods\":" + getTimesAndCommentsJSON(task, startDate, endDate) +"}"; + String resultingJSON = "{\"URL\":\"" + task.getSynchronisingURL()+ "\",\"periods\":" + getTimesAndCommentsJSON(task, startDate, endDate) +"}";
Tu devrais te trouver une petite dépendance qui de permettrais de generer le json de facon plus efficace et maintenable. Genre "json-simple", "gson" ou ... plein d'autre : http://www.json.org/ Ensuite, deux cas soit tu as un objet convertible en Java, soit tu n'en a pas (comme ici). Cela donnerais un code genre: JSONObject response = new JSONObject(); response.put("URL", task.getSynchronisingURL()); response.put("periods", getTimesAndCommentsJSON(task, startDate, endDate)); return response.toString(); C'est un peu plus facile que les concaténations de chaîne.
C'est en effet plus simple, j'ai utilisé gson pour ça, c'est bien plus simple. J'avais commencé par renvoyer un JSONObject avant de réaliser que c'était probablement moins idiot de renvoyer un String au lieu de faire plusieurs fois toString après, du coup j'ai recorrigé ça. On 20/05/2016 18:30, Eric Chatellier wrote:
Le 19/05/2016 09:23, chorem.org scm a écrit :
- String resultingJSON = "{\"uuid\":\"" + task.getName()+ "\",\"periods\":" + getTimesAndCommentsJSON(task, startDate, endDate) +"}"; + String resultingJSON = "{\"URL\":\"" + task.getSynchronisingURL()+ "\",\"periods\":" + getTimesAndCommentsJSON(task, startDate, endDate) +"}";
Tu devrais te trouver une petite dépendance qui de permettrais de generer le json de facon plus efficace et maintenable. Genre "json-simple", "gson" ou ... plein d'autre : http://www.json.org/
Ensuite, deux cas soit tu as un objet convertible en Java, soit tu n'en a pas (comme ici).
Cela donnerais un code genre: JSONObject response = new JSONObject(); response.put("URL", task.getSynchronisingURL()); response.put("periods", getTimesAndCommentsJSON(task, startDate, endDate)); return response.toString();
C'est un peu plus facile que les concaténations de chaîne. _______________________________________________ Jtimer-devel mailing list Jtimer-devel@list.chorem.org http://list.chorem.org/cgi-bin/mailman/listinfo/jtimer-devel
participants (2)
-
Charlène Servantie -
Eric Chatellier