List of usage examples for org.json JSONException toString
public String toString()
From source file:cn.code.notes.gtask.data.TaskList.java
public JSONObject getLocalJSONFromContent() { try {// w ww. j a va 2s . c o m JSONObject js = new JSONObject(); JSONObject folder = new JSONObject(); String folderName = getName(); if (getName().startsWith(GTaskStringUtils.MIUI_FOLDER_PREFFIX)) folderName = folderName.substring(GTaskStringUtils.MIUI_FOLDER_PREFFIX.length(), folderName.length()); folder.put(NoteColumns.SNIPPET, folderName); if (folderName.equals(GTaskStringUtils.FOLDER_DEFAULT) || folderName.equals(GTaskStringUtils.FOLDER_CALL_NOTE)) folder.put(NoteColumns.TYPE, Notes.TYPE_SYSTEM); else folder.put(NoteColumns.TYPE, Notes.TYPE_FOLDER); js.put(GTaskStringUtils.META_HEAD_NOTE, folder); return js; } catch (JSONException e) { Log.e(TAG, e.toString()); e.printStackTrace(); return null; } }
From source file:com.pti.mates.ServerUtilities.java
public static void sendPreferences(SharedPreferences prefs, Context ctx) { //enviar preferencies al server Log.v(LogConstants.LOG_SERVERUTILITIES, "radius = " + prefs.getString(Common.RADIUS_KEY, "Empty")); Log.v(LogConstants.LOG_SERVERUTILITIES, "gender = " + prefs.getString(Common.GENDER_KEY, "Empty")); Log.v(LogConstants.LOG_SERVERUTILITIES, "interested in = " + prefs.getString(Common.INTERESTED_IN_KEY, "Empty")); String fbid = Common.getFBID(); DefaultHttpClient client = new MyHttpClient(ctx); HttpPost post = new HttpPost("https://54.194.14.115:443/user"); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); nameValuePairs.add(new BasicNameValuePair("id", fbid)); try {//from w w w . j a v a 2 s .c om post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } // Execute the Post call and obtain the response HttpResponse postResponse; JSONObject user; try { postResponse = client.execute(post); HttpEntity responseEntity = postResponse.getEntity(); InputStream is = responseEntity.getContent(); try { user = new JSONObject(convertStreamToString(is)); user.put("gender", prefs.getString(Common.GENDER_KEY, "Empty")); user.put("interested_in", prefs.getString(Common.INTERESTED_IN_KEY, "Empty")); user.put("distance", prefs.getString(Common.RADIUS_KEY, "Empty")); updatePreferences(user, ctx, fbid); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (ClientProtocolException e) { Log.e("ERROR", e.toString()); e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); Log.e("ERROR", e.toString()); s = "ERROR: " + e.toString() + " :("; } Log.d("CHIVATO", "FIN THREAD"); }
From source file:com.t2.compassionMeditation.MeditationActivity.java
/** * Receives a json string containing data about all of the paired sensors * the adds a new BioSensor for each one to the mBioSensors collection * /*w w w . j a va2s .com*/ * @param jsonString String containing info on all paired devices */ private void populateBioSensors(String jsonString) { Log.d(TAG, this.getClass().getSimpleName() + " populateBioSensors"); // Now clear it out and populate it. The only difference is that // if a sensor previously existed, then mBioSensors.clear(); try { JSONArray jsonArray = new JSONArray(jsonString); for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject = jsonArray.getJSONObject(i); Boolean enabled = jsonObject.getBoolean("enabled"); String name = jsonObject.getString("name"); String address = jsonObject.getString("address"); int connectionStatus = jsonObject.getInt("connectionStatus"); if (name.equalsIgnoreCase("system")) { mBluetoothEnabled = enabled; } else { Log.i(TAG, "Adding sensor " + name + ", " + address + (enabled ? ", enabled" : ", disabled") + " : " + Util.connectionStatusToString(connectionStatus)); BioSensor bioSensor = new BioSensor(name, address, enabled); bioSensor.mConnectionStatus = connectionStatus; mBioSensors.add(bioSensor); } } } catch (JSONException e) { Log.e(TAG, e.toString()); } }
From source file:com.t2.compassionMeditation.Graphs1Activity.java
/** * Receives a json string containing data about all of the paired sensors * the adds a new BioSensor for each one to the mBioSensors collection * /* ww w . j a v a 2 s . c o m*/ * @param jsonString String containing info on all paired devices */ private void populateBioSensors(String jsonString) { Log.d(TAG, this.getClass().getSimpleName() + " populateBioSensors"); // Now clear it out and populate it. The only difference is that // if a sensor previously existed, then mBioSensors.clear(); try { JSONArray jsonArray = new JSONArray(jsonString); for (int i = 0; i < jsonArray.length(); i++) { JSONObject jsonObject = jsonArray.getJSONObject(i); Boolean enabled = jsonObject.getBoolean("enabled"); String name = jsonObject.getString("name"); String address = jsonObject.getString("address"); int connectionStatus = jsonObject.getInt("connectionStatus"); if (name.equalsIgnoreCase("system")) { mBluetoothEnabled = enabled; } else { Log.d(TAG, "Adding sensor " + name + ", " + address + (enabled ? ", enabled" : ", disabled") + " : " + Util.connectionStatusToString(connectionStatus)); BioSensor bioSensor = new BioSensor(name, address, enabled); bioSensor.mConnectionStatus = connectionStatus; mBioSensors.add(bioSensor); } } } catch (JSONException e) { Log.e(TAG, e.toString()); } }
From source file:org.openmrs.mobile.listeners.findPatients.FindPatientListener.java
@Override public void onResponse(JSONObject response) { List<Patient> patientsList = new ArrayList<Patient>(); mLogger.d(response.toString());/*from w ww .j a v a 2s. c o m*/ try { JSONArray patientsJSONList = response.getJSONArray(BaseManager.RESULTS_KEY); for (int i = 0; i < patientsJSONList.length(); i++) { patientsList.add(PatientMapper.map(patientsJSONList.getJSONObject(i))); } mActivityCaller.updatePatientsData(mSearchId, patientsList); } catch (JSONException e) { mLogger.d(e.toString()); } }
From source file:com.cmackay.plugins.googleanalytics.GoogleAnalyticsPlugin.java
private void setTrackingId(String rawArgs, CallbackContext callback) { try {/*from w w w .j a v a2 s . c om*/ tracker = ga.newTracker(new JSONArray(rawArgs).getString(0)); // setup uncaught exception handler tracker.enableExceptionReporting(true); callback.success(); } catch (JSONException e) { callback.error(e.toString()); } }
From source file:com.cmackay.plugins.googleanalytics.GoogleAnalyticsPlugin.java
private void setDispatchInterval(String rawArgs, CallbackContext callback) { try {//from w ww .ja v a2s.com ga.setLocalDispatchPeriod(new JSONArray(rawArgs).getInt(0)); callback.success(); } catch (JSONException e) { callback.error(e.toString()); } }
From source file:com.cmackay.plugins.googleanalytics.GoogleAnalyticsPlugin.java
private void setLogLevel(String rawArgs, CallbackContext callbackContext) { if (hasTracker(callbackContext)) { try {/* w w w. ja va2 s .c o m*/ int level = new JSONArray(rawArgs).getInt(0); int logLevel = LogLevel.WARNING; switch (level) { case 0: logLevel = LogLevel.VERBOSE; break; case 1: logLevel = LogLevel.INFO; break; case 2: logLevel = LogLevel.WARNING; break; case 3: logLevel = LogLevel.ERROR; break; } ga.getLogger().setLogLevel(logLevel); callbackContext.success(); } catch (JSONException e) { callbackContext.error(e.toString()); } } }
From source file:com.cmackay.plugins.googleanalytics.GoogleAnalyticsPlugin.java
private void get(String rawArgs, CallbackContext callbackContext) { if (hasTracker(callbackContext)) { try {/* w w w. j av a 2 s. com*/ String value = tracker.get(new JSONArray(rawArgs).getString(0)); callbackContext.success(value); } catch (JSONException e) { callbackContext.error(e.toString()); } } }
From source file:com.cmackay.plugins.googleanalytics.GoogleAnalyticsPlugin.java
private void set(String rawArgs, CallbackContext callbackContext) { if (hasTracker(callbackContext)) { try {//from w w w.java2s .c o m JSONArray args = new JSONArray(rawArgs); String key = args.getString(0); String value = args.isNull(1) ? null : args.getString(1); tracker.set(key, value); callbackContext.success(); } catch (JSONException e) { callbackContext.error(e.toString()); } } }