List of usage examples for org.json JSONObject toString
public String toString()
From source file:reseau.jeu.serveur.Protocole.java
public static String construireMsgChat(String message, int cible) { JSONObject msg = new JSONObject(); try {//from w w w .ja va 2s . c om msg.put("TYPE", JOUEUR_MESSAGE); msg.put("CIBLE", cible); msg.put("MESSAGE", message); } catch (JSONException e) { e.printStackTrace(); } return msg.toString(); }
From source file:reseau.jeu.serveur.Protocole.java
public static String construireMsgChangerEquipe(int etat) { JSONObject msg = new JSONObject(); try {/*from ww w.j a v a2 s . c o m*/ msg.put("TYPE", JOUEUR_CHANGER_EQUIPE); msg.put("STATUS", etat); } catch (JSONException jsone) { jsone.printStackTrace(); } return msg.toString(); }
From source file:reseau.jeu.serveur.Protocole.java
public static String construireMsgCreatureArrivee(Creature creature) { JSONObject msg = new JSONObject(); try {//from w w w .ja v a 2 s .co m msg.put("TYPE", CREATURE_ARRIVEE); msg.put("ID_CREATURE", creature.getId()); } catch (JSONException jsone) { jsone.printStackTrace(); } return msg.toString(); }
From source file:reseau.jeu.serveur.Protocole.java
public static String construireMsgMessage(int idAuteur, String contenu) { JSONObject msg = new JSONObject(); try {/*from w w w . j ava2 s .co m*/ // Construction de la structure JSON msg.put("TYPE", JOUEUR_MESSAGE); msg.put("ID_JOUEUR", idAuteur); msg.put("MESSAGE", contenu); } catch (JSONException jsone) { jsone.printStackTrace(); } return msg.toString(); }
From source file:reseau.jeu.serveur.Protocole.java
public static String construireMsgJoueurDeconnecte(int idJoueur) { JSONObject msg = new JSONObject(); try {/* ww w . j a v a 2 s .c o m*/ // Construction de la structure JSON msg.put("TYPE", JOUEUR_DECONNEXION); msg.put("ID_JOUEUR", idJoueur); } catch (JSONException jsone) { jsone.printStackTrace(); } return msg.toString(); }
From source file:reseau.jeu.serveur.Protocole.java
public static String construireMsgEquipeAPerdue(int id) { JSONObject msg = new JSONObject(); try {//from www . j a v a 2 s .com // Construction de la structure JSON msg.put("TYPE", EQUIPE_A_PERDUE); msg.put("ID_EQUIPE", id); } catch (JSONException jsone) { jsone.printStackTrace(); } return msg.toString(); }
From source file:tech.salroid.filmy.network_stuff.FirstFetch.java
private void syncNowInTheaters() { String api_key = BuildConfig.API_KEY; final String Intheatres_Base_URL = "https://api.themoviedb.org/3/movie/now_playing?api_key=" + api_key; JsonObjectRequest IntheatresJsonObjectRequest = new JsonObjectRequest(Intheatres_Base_URL, null, new Response.Listener<JSONObject>() { @Override// w w w.jav a 2 s.co m public void onResponse(JSONObject response) { intheatresparseOutput(response.toString(), 2); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.e("webi", "Volley Error: " + error.getCause()); } }); tmdbrequestQueue.add(IntheatresJsonObjectRequest); }
From source file:tech.salroid.filmy.network_stuff.FirstFetch.java
private void syncNowUpComing() { String api_key = BuildConfig.API_KEY; final String Upcoming_Base_URL = "https://api.themoviedb.org/3/movie/upcoming?api_key=" + api_key; JsonObjectRequest UpcomingJsonObjectRequest = new JsonObjectRequest(Upcoming_Base_URL, null, new Response.Listener<JSONObject>() { @Override// w w w . ja va2s. c o m public void onResponse(JSONObject response) { upcomingparseOutput(response.toString()); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.e("webi", "Volley Error: " + error.getCause()); } }); tmdbrequestQueue.add(UpcomingJsonObjectRequest); }
From source file:tech.salroid.filmy.network_stuff.FirstFetch.java
private void syncNowTrending() { String api_key = BuildConfig.API_KEY; final String BASE_URL = "https://api.themoviedb.org/3/movie/popular?api_key=" + api_key; JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(BASE_URL, null, new Response.Listener<JSONObject>() { @Override// w w w . ja v a 2s. c o m public void onResponse(JSONObject response) { parseOutput(response.toString()); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { NetworkResponse networkResponse = error.networkResponse; if (networkResponse != null) { sendFetchFailedMessage(networkResponse.statusCode); } else { sendFetchFailedMessage(00); } } }); tmdbrequestQueue.add(jsonObjectRequest); }
From source file:org.ohmage.reminders.types.location.LocTrigService.java
private void uploadLatestLocation() { final String KEY_LOC_LAT = "latitude"; final String KEY_LOC_LONG = "longitude"; final String KEY_LOC_ACC = "accuracy"; final String KEY_LOC_PROVIDER = "provider"; final String KEY_LOC_TIME = "time"; final String TIME_STAMP_FORMAT = "yyyy-MM-dd HH:mm:ss"; //Check if any location update has been received if (mLastKnownLocTime == 0 || mLastKnownLoc == null) { return;//from ww w .ja v a 2s.co m } //If 'upload always' is not enabled, check for the //compile time constants and upload only if it is //allowed if (!mLocTraceUploadAlways) { //Check if the user has moved at least the distance specified if (mLastKnownLoc.distanceTo(mLastLocTrace) < LocTrigConfig.LOC_TRACE_MIN_DISTANCE_FOR_UPLOAD) { //Before discarding the trace, check the time stamp //of the last upload. If it has been longer than the //specified time, upload. if (mLastKnownLoc.getTime() - mLastLocTrace.getTime() < LocTrigConfig.LOC_TRACE_MAX_GAP_BETWEEN_UPLOADS) { Log.v(TAG, "LocTrigService: Skipping the location" + " trace upload"); return; } } } //TODO move loc to JSON conversion to a common place //The trigger details upload also has the same logic JSONObject jLoc = new JSONObject(); try { jLoc.put(KEY_LOC_LAT, mLastKnownLoc.getLatitude()); jLoc.put(KEY_LOC_LONG, mLastKnownLoc.getLongitude()); jLoc.put(KEY_LOC_ACC, mLastKnownLoc.getAccuracy()); jLoc.put(KEY_LOC_PROVIDER, mLastKnownLoc.getProvider()); SimpleDateFormat dateFormat = new SimpleDateFormat(TIME_STAMP_FORMAT); jLoc.put(KEY_LOC_TIME, dateFormat.format(new Date(mLastKnownLoc.getTime()))); } catch (JSONException e) { Log.e(TAG, "LocTrigService: Error while converting " + " location to JSON for tracing", e); return; } String msg = "Location trace: " + jLoc.toString(); //Upload the trace using LogProbe Log.v(TAG, "LocTrigService: Upload location trace: " + msg); //Save this location locally mLastLocTrace.set(mLastKnownLoc); }