List of usage examples for org.json JSONObject getInt
public int getInt(String key) throws JSONException
From source file:com.mjhram.ttaxi.gcm_client.MyGcmListenerService.java
/** * Called when message is received./* w ww. j a v a 2s . c o m*/ * * @param from SenderID of the sender. * @param data Data bundle containing message data as key/value pairs. * For Set of keys use data.keySet(). */ // [START receive_message] @Override public void onMessageReceived(String from, Bundle data) { String message = data.getString("message"); Log.d(TAG, "From: " + from); Log.d(TAG, "Message: " + message); if (from.startsWith("/topics/")) { // message received from some topic. } else { try { String tag; JSONObject msgObj; msgObj = new JSONObject(message); tag = msgObj.getString("tag"); if (tag.equalsIgnoreCase("drvId")) { int drvId = msgObj.getInt("data");//Integer.parseInt(message); EventBus.getDefault().post(new ServiceEvents.TRequestAccepted(drvId)); message = Integer.toString(drvId); /*Intent intent = new Intent(Constants.UPDATE_REQ); //put whatever data you want to send, if any intent.putExtra("drvId", drvId); //send broadcast getApplicationContext().sendBroadcast(intent);*/ // normal downstream message. } else if (tag.equalsIgnoreCase("treqState")) { String state = msgObj.getString("data");//Integer.parseInt(message); EventBus.getDefault().post(new ServiceEvents.TRequestUpdated(state)); message = getString(R.string.gcmClientReqState) + state; /*Intent intent = new Intent(Constants.UPDATE_REQ); //put whatever data you want to send, if any intent.putExtra("drvId", drvId); //send broadcast getApplicationContext().sendBroadcast(intent);*/ // normal downstream message. } else if (tag.equalsIgnoreCase("drvLoc")) { DriverInfo driverInfo = new DriverInfo(); driverInfo.driverId = msgObj.getInt("drvId"); driverInfo.latitude = msgObj.getDouble("lat"); driverInfo.longitude = msgObj.getDouble("lng"); EventBus.getDefault().post(new ServiceEvents.DriverLocationUpdate(driverInfo)); } } catch (JSONException e) { e.printStackTrace(); } } sendNotification(message); // [END_EXCLUDE] }
From source file:org.prx.prp.model.Episode.java
public Episode(JSONObject c) { super();// w w w . j a v a2s .co m try { this.episodeId = c.getInt("id"); this.programId = c.getInt("program_id"); this.title = c.getString("title"); this.summary = c.getString("summary"); this.published = c.getString("published"); this.url = c.getString("url"); this.enclosure = c.getString("enclosure"); c.getString("enclosure_type"); this.enclosureLength = c.getInt("enclosure_length"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.nokia.example.capturetheflag.network.model.Game.java
public Game(final JSONObject jsonObj) throws JSONException { this(jsonObj.getInt(ModelConstants.ID_KEY)); setName(jsonObj.getString(ModelConstants.NAME_KEY)); JSONArray jsonArray = jsonObj.getJSONArray(ModelConstants.PLAYERS_KEY); for (int i = 0; i < jsonArray.length(); i++) { Player p = new Player(jsonArray.getJSONObject(i)); addPlayer(p);/* w ww . ja v a 2 s .com*/ } JSONObject redflag = jsonObj.getJSONObject(ModelConstants.RED_FLAG_KEY); JSONObject blueflag = jsonObj.getJSONObject(ModelConstants.BLUE_FLAG_KEY); mRedFlag = new Flag(redflag.getDouble(ModelConstants.LATITUDE_KEY), redflag.getDouble(ModelConstants.LONGITUDE_KEY)); mBlueFlag = new Flag(blueflag.getDouble(ModelConstants.LATITUDE_KEY), blueflag.getDouble(ModelConstants.LONGITUDE_KEY)); mIsPremium = jsonObj.optBoolean(ModelConstants.IS_PREMIUM_KEY, false); }
From source file:org.emr.controller.ApplicationController.java
@RequestMapping(value = "/page") public ModelAndView home(@RequestParam("json") String jsonString) { ModelAndView mv = new ModelAndView(); JSONObject json; System.out.println("page request"); try {//from www .j av a2 s. c o m System.out.println(jsonString); json = new JSONObject(jsonString); int pageid = json.has("pageid") ? json.getInt("pageid") : 0; switch (pageid) { case 2: mv.setViewName("index.html"); break; default: mv.setViewName("login.html"); break; } } catch (Exception e) { e.printStackTrace(); } // mv.setViewName("index.html"); return mv; }
From source file:config.Manejador.java
public boolean update(JSONObject criteria, JSONObject changes) throws JSONException, IOException { JSONObject js_obj = new JSONObject(this.src_archivo); JSONArray js_array = (JSONArray) js_obj.get(this.nom_coleccion); boolean retorno = false; JSONObject busqueda = this.Select(criteria); if (!busqueda.equals(this.dont_exists)) { Iterator it_changes = changes.keys(); while (it_changes.hasNext()) { String key_c = it_changes.next().toString(); busqueda.put(key_c, changes.get(key_c)); }//from w w w . j a v a 2 s . c o m int idx = busqueda.getInt("idx"); busqueda.remove("idx"); js_obj.put(this.nom_coleccion, js_array.put(idx, busqueda)); retorno = true; } this.src_archivo = js_obj.toString(4); this.saveFile(); return retorno; }
From source file:config.Manejador.java
public boolean updateIntoArray(JSONObject criteria, JSONObject changes) throws JSONException, IOException { boolean retorno = false; JSONObject js_obj = new JSONObject(this.src_archivo); JSONArray js_array = (JSONArray) js_obj.get(this.nom_coleccion); if (criteria.has("idx")) { int idx_registro = criteria.getInt("idx"); JSONObject registro = js_array.getJSONObject(idx_registro); JSONArray arr_registro, arr_criteria, arr_changes; JSONObject obj_arr_registro, obj_arr_criteria, obj_arr_changes; Iterator it_changes = changes.keys(); while (it_changes.hasNext()) { String key = it_changes.next().toString(); int idx_arr_registro = 0; arr_registro = registro.getJSONArray(key); arr_criteria = criteria.getJSONArray(key); arr_changes = changes.getJSONArray(key); obj_arr_criteria = arr_criteria.getJSONObject(0); obj_arr_changes = arr_changes.getJSONObject(0); idx_arr_registro = obj_arr_criteria.getInt("idx"); obj_arr_registro = arr_registro.getJSONObject(idx_arr_registro); Iterator field_changes = obj_arr_changes.keys(); while (field_changes.hasNext()) { String key_change = field_changes.next().toString(); obj_arr_registro.put(key_change, obj_arr_changes.get(key_change)); }/*from ww w . j a va 2s. co m*/ arr_registro.put(idx_arr_registro, obj_arr_registro); registro.put(key, arr_registro); js_obj.put(this.nom_coleccion, js_array.put(idx_registro, registro)); retorno = true; } } this.src_archivo = js_obj.toString(4); this.saveFile(); return retorno; }
From source file:config.Manejador.java
public boolean delete(JSONObject criteria) throws JSONException, IOException { boolean retorno = false; JSONObject js_obj = new JSONObject(this.src_archivo); JSONArray js_array = (JSONArray) js_obj.get(this.nom_coleccion); JSONObject busqueda = this.Select(criteria); if (!busqueda.equals(this.dont_exists)) { System.out.println(busqueda.toString(4)); int indice = busqueda.getInt("idx"); System.out.println(indice); js_array.remove(indice);//from www . jav a 2s . c om js_obj.put(this.nom_coleccion, js_array); retorno = true; this.src_archivo = js_obj.toString(4); this.saveFile(); } return retorno; }
From source file:config.Manejador.java
public boolean deleteIntoArray(JSONObject criteria, JSONObject target) throws JSONException, IOException { boolean retorno = false; JSONObject js_obj = new JSONObject(this.src_archivo); JSONArray js_array = (JSONArray) js_obj.get(this.nom_coleccion); System.out.println(criteria.toString(4)); if (criteria.has("idx")) { int idx_registro = criteria.getInt("idx"); int idx_arr_obj = 0; JSONObject registro = js_array.getJSONObject(idx_registro); JSONArray arr_registro, arr_criteria; JSONObject obj_arr_criteria;/* w w w. j ava 2s . co m*/ Iterator it_target = target.keys(); if (it_target.hasNext()) { String key = it_target.next().toString(); arr_registro = registro.getJSONArray(key); arr_criteria = criteria.getJSONArray(key); obj_arr_criteria = arr_criteria.getJSONObject(0); idx_arr_obj = obj_arr_criteria.getInt("idx"); arr_registro.remove(idx_arr_obj); registro.put(key, arr_registro); js_array.put(idx_registro, registro); js_obj.put(this.nom_coleccion, js_array); retorno = true; this.src_archivo = js_obj.toString(4); this.saveFile(); } } return retorno; }
From source file:au.id.tmm.anewreader.model.PreviousAccountInfoFile.java
/** * Attempts to retrieve the version number of the file. *//*from w ww . ja v a 2 s . c o m*/ private int retrieveVersion(int version) throws UnableToRetrieveVersionException, IOException { try { switch (version) { case 1: JSONObject previousAccountInfo = new JSONObject( IOUtils.readFileAsString(infoFile, DEFAULT_ENCODING)); return previousAccountInfo.getInt(VERSION_KEY); default: throw new UnableToRetrieveVersionException(); } } catch (JSONException e) { throw new UnableToRetrieveVersionException(e); } }
From source file:com.dwdesign.tweetings.util.Utils.java
public static Bundle parseArguments(final String string) { final Bundle bundle = new Bundle(); if (string != null) { try {//from ww w . j av a 2 s. c o m final JSONObject json = new JSONObject(string); final Iterator<?> it = json.keys(); while (it.hasNext()) { final Object key_obj = it.next(); if (key_obj == null) { continue; } final String key = key_obj.toString(); final Object value = json.get(key); if (value instanceof Boolean) { bundle.putBoolean(key, json.getBoolean(key)); } else if (value instanceof Integer) { // Simple workaround for account_id if (INTENT_KEY_ACCOUNT_ID.equals(key)) { bundle.putLong(key, json.getLong(key)); } else { bundle.putInt(key, json.getInt(key)); } } else if (value instanceof Long) { bundle.putLong(key, json.getLong(key)); } else if (value instanceof String) { bundle.putString(key, json.getString(key)); } else { Log.w(LOGTAG, "Unknown type " + value.getClass().getSimpleName() + " in arguments key " + key); } } } catch (final JSONException e) { e.printStackTrace(); } catch (final ClassCastException e) { e.printStackTrace(); } } return bundle; }