1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- package rsx;
- import org.json.JSONObject;
- import org.json.JSONException;
- /**
- * Analyse reponse d'un serveur BomberStudent
- *
- * @author Arthur Brandao
- */
- public class BomberStudentReponse {
- /**
- * Reponse valide ou non
- */
- protected boolean error = true;
-
- /**
- * Code du statut encoyé par le serveur
- */
- protected int statut;
-
- /**
- * Message du statut envoyé par le serveur
- */
- protected String message;
-
- /**
- * Information en JSON envoyé par le serveur
- */
- protected JSONObject reponse = null;
- /* --- Constructeurs --- */
- /**
- * Constructeur par defaut en cas de reponse invalide
- */
- public BomberStudentReponse() {
- }
- /**
- * Parse la reponse du serveur
- * @param reponse La reponse en JSON à parser
- */
- public BomberStudentReponse(String reponse) {
- this.error = false;
- //Parse reponse
- try {
- JSONObject json = new JSONObject(reponse);
- this.statut = json.getInt("statut");
- this.message = json.getString("message");
- if(json.has("param")){
- this.reponse = json.getJSONObject("param");
- }
- this.error = false;
- } catch(JSONException ex){
- System.err.println("La reponse n'est pas en JSON : " + ex.getMessage());
- }
- }
- /* --- Getter/Setter --- */
- public boolean isError() {
- return error;
- }
- public void setError(boolean error) {
- this.error = error;
- }
- public int getStatut() {
- return statut;
- }
- public void setStatut(int statut) {
- this.statut = statut;
- }
- public String getMessage() {
- return message;
- }
- public void setMessage(String message) {
- this.message = message;
- }
- public JSONObject getReponse() {
- return reponse;
- }
- public void setReponse(JSONObject reponse) {
- this.reponse = reponse;
- }
- }
|