List of usage examples for org.json JSONException toString
public String toString()
From source file:cz.muni.fi.japanesedictionary.entity.JapaneseCharacter.java
/** * Takes json string and parses it to list of russian meanings. * * @param jsonString - JSON string to be parsed *//*from ww w. j av a2 s .com*/ public void parseMeaningRussian(String jsonString) { if (jsonString == null || jsonString.length() < 1) { return; } List<String> temp; JSONArray parseJSON; try { parseJSON = new JSONArray(jsonString); } catch (JSONException e) { Log.w(LOG_TAG, "parsing parseMeaningRussian() - initial expression failed: " + e.toString()); return; } temp = this.parseOneJSONArray(parseJSON); for (String str : temp) { this.addMeaningRussian(str); } }
From source file:cz.muni.fi.japanesedictionary.entity.JapaneseCharacter.java
/** * Takes json string and parses it to list of nanori. * /*from w w w. j a va2 s.c o m*/ * @param jsonString - JSON string to be parsed */ public void parseNanori(String jsonString) { if (jsonString == null || jsonString.length() < 1) { return; } List<String> temp; JSONArray parseJSON; try { parseJSON = new JSONArray(jsonString); } catch (JSONException e) { Log.w(LOG_TAG, "parsing parseNanori() - initial expression failed: " + e.toString()); return; } temp = this.parseOneJSONArray(parseJSON); for (String str : temp) { this.addNanori(str); } }
From source file:cz.muni.fi.japanesedictionary.entity.JapaneseCharacter.java
/** * Universal privatemethod for parsing JSON array. * /* w w w . ja v a2 s.com*/ * @param sense - JSONArray to be parsed */ private List<String> parseOneJSONArray(JSONArray sense) { if (sense == null) { return null; } List<String> temp = new ArrayList<>(); for (int k = 0; k < sense.length(); k++) { String value; try { value = sense.getString(k); temp.add(value); } catch (JSONException e) { Log.w(LOG_TAG, "getting parseOneSense() expression failed: " + e.toString()); e.printStackTrace(); } } return temp; }
From source file:org.openmrs.mobile.listeners.visit.VisitTypeListener.java
@Override public void onResponse(JSONObject response) { mLogger.d(response.toString());/*w w w . j a v a 2 s. c o m*/ try { JSONArray visitTypesObj = response.getJSONArray("results"); String visitTypeUUID = ((JSONObject) visitTypesObj.get(0)).getString("uuid"); OpenMRS.getInstance().setVisitTypeUUID(visitTypeUUID); } catch (JSONException e) { mLogger.d(e.toString()); } }
From source file:com.nextgis.firereporter.SettingsSupport.java
public SettingsSupport(Context context, PreferenceScreen screen) { this.screen = screen; this.context = context; // Load the preferences from an XML resource //addPreferencesFromResource(R.xml.preferences); mSendDataIntervalPref = (ListPreference) screen.findPreference(SettingsActivity.KEY_PREF_INTERVAL); if (mSendDataIntervalPref != null) { int index = mSendDataIntervalPref.findIndexOfValue(mSendDataIntervalPref.getValue()); if (index >= 0) { mSendDataIntervalPref.setSummary(mSendDataIntervalPref.getEntries()[index]); } else {// w ww. jav a 2s . c om mSendDataIntervalPref.setSummary((String) mSendDataIntervalPref.getValue()); } } mSaveBattPref = (CheckBoxPreference) screen.findPreference(SettingsActivity.KEY_PREF_SERVICE_BATT_SAVE); if (mSaveBattPref != null) mSaveBattPref.setSummary(mSaveBattPref.isChecked() ? R.string.stOn : R.string.stOff); mNotifyLEDPref = (CheckBoxPreference) screen.findPreference(SettingsActivity.KEY_PREF_NOTIFY_LED); if (mNotifyLEDPref != null) mNotifyLEDPref.setSummary(mNotifyLEDPref.isChecked() ? R.string.stOn : R.string.stOff); mPlaySoundPref = (CheckBoxPreference) screen.findPreference(SettingsActivity.KEY_PREF_NOTIFY_SOUND); if (mPlaySoundPref != null) mPlaySoundPref.setSummary(mPlaySoundPref.isChecked() ? R.string.stOn : R.string.stOff); mVibroPref = (CheckBoxPreference) screen.findPreference(SettingsActivity.KEY_PREF_NOTIFY_VIBRO); if (mVibroPref != null) mVibroPref.setSummary(mVibroPref.isChecked() ? R.string.stOn : R.string.stOff); mRowCountPref = (EditTextPreference) screen.findPreference(SettingsActivity.KEY_PREF_ROW_COUNT); if (mRowCountPref != null) mRowCountPref.setSummary((String) mRowCountPref.getText()); mFireSearchRadiusPref = (EditTextPreference) screen .findPreference(SettingsActivity.KEY_PREF_FIRE_SEARCH_RADIUS); if (mFireSearchRadiusPref != null) mFireSearchRadiusPref .setSummary((String) mFireSearchRadiusPref.getText() + " " + context.getString(R.string.km)); mDayIntervalPref = (ListPreference) screen.findPreference(SettingsActivity.KEY_PREF_SEARCH_DAY_INTERVAL); if (mDayIntervalPref != null) { int index = mDayIntervalPref.findIndexOfValue(mDayIntervalPref.getValue()); if (index >= 0) { mDayIntervalPref.setSummary(mDayIntervalPref.getEntries()[index]); } else { mDayIntervalPref.setSummary((String) mDayIntervalPref.getValue()); } } mSearchCurrentDatePref = (CheckBoxPreference) screen .findPreference(SettingsActivity.KEY_PREF_SEARCH_CURR_DAY); if (mSearchCurrentDatePref != null) mSearchCurrentDatePref.setSummary(mSearchCurrentDatePref.isChecked() ? R.string.stSearchCurrentDayOn : R.string.stSearchCurrentDayOff); mNasaServerPref = (EditTextPreference) screen.findPreference(SettingsActivity.KEY_PREF_SRV_NASA); if (mNasaServerPref != null) mNasaServerPref.setSummary((String) mNasaServerPref.getText()); mNasaServerUserPref = (EditTextPreference) screen.findPreference(SettingsActivity.KEY_PREF_SRV_NASA_USER); if (mNasaServerUserPref != null) mNasaServerUserPref.setSummary((String) mNasaServerUserPref.getText()); mUserServerPref = (EditTextPreference) screen.findPreference(SettingsActivity.KEY_PREF_SRV_USER); if (mUserServerPref != null) mUserServerPref.setSummary((String) mUserServerPref.getText()); mUserServerUserPref = (EditTextPreference) screen.findPreference(SettingsActivity.KEY_PREF_SRV_USER_USER); if (mUserServerUserPref != null) mUserServerUserPref.setSummary((String) mUserServerUserPref.getText()); mScanServerUserPref = (EditTextPreference) screen.findPreference(SettingsActivity.KEY_PREF_SRV_SCAN_USER); if (mScanServerUserPref != null) mScanServerUserPref.setSummary((String) mScanServerUserPref.getText()); mNasaServerPassPref = (EditTextPreference) screen.findPreference(SettingsActivity.KEY_PREF_SRV_NASA_PASS); mUserServerPassPref = (EditTextPreference) screen.findPreference(SettingsActivity.KEY_PREF_SRV_USER_PASS); mScanServerPassPref = (EditTextPreference) screen.findPreference(SettingsActivity.KEY_PREF_SRV_SCAN_PASS); final Preference checkNasaConnPref = (Preference) screen .findPreference(SettingsActivity.KEY_PREF_SRV_NASA_CHECK_CONN); final Preference checkUserConnPref = (Preference) screen .findPreference(SettingsActivity.KEY_PREF_SRV_USER_CHECK_CONN); final Preference checkScanConnPref = (Preference) screen .findPreference(SettingsActivity.KEY_PREF_SRV_SCAN_CHECK_CONN); mReturnHandler = new Handler() { @SuppressLint("NewApi") public void handleMessage(Message msg) { Bundle resultData = msg.getData(); boolean bHaveErr = resultData.getBoolean(GetFiresService.ERROR); int nType = resultData.getInt(GetFiresService.SOURCE); if (bHaveErr) { Toast.makeText(SettingsSupport.this.context, resultData.getString(GetFiresService.ERR_MSG), Toast.LENGTH_LONG).show(); if (nType == 1) {//user checkUserConnPref.setSummary(R.string.stConnectionFailed); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) checkUserConnPref.setIcon(R.drawable.ic_alerts_and_states_error); } else if (nType == 2) {//nasa checkNasaConnPref.setSummary(R.string.stConnectionFailed); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) checkNasaConnPref.setIcon(R.drawable.ic_alerts_and_states_error); } else if (nType == 3) {//scanex checkScanConnPref.setSummary(R.string.stConnectionFailed); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) checkScanConnPref.setIcon(R.drawable.ic_alerts_and_states_error); } } else { String sData = resultData.getString(GetFiresService.JSON); if (nType == 1) {//user JSONObject jsonMainObject; try { jsonMainObject = new JSONObject(sData); if (jsonMainObject.getBoolean("error")) { String sMsg = jsonMainObject.getString("msg"); Toast.makeText(SettingsSupport.this.context, sMsg, Toast.LENGTH_LONG).show(); checkUserConnPref.setSummary(R.string.stConnectionFailed); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) checkUserConnPref.setIcon(R.drawable.ic_alerts_and_states_error); } else { checkUserConnPref.setSummary(R.string.stConnectionSucceeded); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) checkUserConnPref.setIcon(R.drawable.ic_navigation_accept); } } catch (JSONException e) { Toast.makeText(SettingsSupport.this.context, e.toString(), Toast.LENGTH_LONG).show(); e.printStackTrace(); checkUserConnPref.setSummary(R.string.sCheckDBConnSummary); } } else if (nType == 2) {//nasa JSONObject jsonMainObject; try { jsonMainObject = new JSONObject(sData); if (jsonMainObject.getBoolean("error")) { String sMsg = jsonMainObject.getString("msg"); Toast.makeText(SettingsSupport.this.context, sMsg, Toast.LENGTH_LONG).show(); checkNasaConnPref.setSummary(R.string.stConnectionFailed); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) checkNasaConnPref.setIcon(R.drawable.ic_alerts_and_states_error); } else { checkNasaConnPref.setSummary(R.string.stConnectionSucceeded); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) checkNasaConnPref.setIcon(R.drawable.ic_navigation_accept); } } catch (JSONException e) { Toast.makeText(SettingsSupport.this.context, e.toString(), Toast.LENGTH_LONG).show(); e.printStackTrace(); checkNasaConnPref.setSummary(R.string.sCheckDBConnSummary); } } else if (nType == 3) {//scanex if (sData.length() == 0) { String sMsg = "Connect failed"; Toast.makeText(SettingsSupport.this.context, sMsg, Toast.LENGTH_LONG).show(); checkScanConnPref.setSummary(R.string.stConnectionFailed); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) checkScanConnPref.setIcon(R.drawable.ic_alerts_and_states_error); } else { checkScanConnPref.setSummary(R.string.stConnectionSucceeded); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) checkScanConnPref.setIcon(R.drawable.ic_navigation_accept); new HttpGetter(SettingsSupport.this.context, 4, SettingsSupport.this.context.getString(R.string.stChecking), mReturnHandler, true).execute( "http://fires.kosmosnimki.ru/SAPI/Account/Get/?CallBackName=" + GetFiresService.USER_ID, sData); } } else if (nType == 4) {//scanex detailes try { String sSubData = GetFiresService.removeJsonT(sData); JSONObject rootobj = new JSONObject(sSubData); String sStatus = rootobj.getString("Status"); if (sStatus.equals("OK")) { JSONObject resobj = rootobj.getJSONObject("Result"); String sName = ""; if (!resobj.isNull("FullName")) sName = resobj.getString("FullName"); String sPhone = ""; if (!resobj.isNull("Phone")) sPhone = resobj.getString("Phone"); //add properties if (sPhone.length() > 0) { Preference PhonePref = new Preference(SettingsSupport.this.context); PhonePref.setTitle(R.string.stScanexServerUserPhone); PhonePref.setSummary(sPhone); PhonePref.setOrder(2); SettingsSupport.this.screen.addPreference(PhonePref); } if (sName.length() > 0) { Preference NamePref = new Preference(SettingsSupport.this.context); NamePref.setTitle(R.string.stScanexServerUserFullName); NamePref.setSummary(sName); NamePref.setOrder(2); SettingsSupport.this.screen.addPreference(NamePref); } } else { Toast.makeText(SettingsSupport.this.context, rootobj.getString("ErrorInfo"), Toast.LENGTH_LONG).show(); } } catch (JSONException e) { Toast.makeText(SettingsSupport.this.context, e.toString(), Toast.LENGTH_LONG).show(); e.printStackTrace(); } } } }; }; if (checkNasaConnPref != null) checkNasaConnPref.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { String sURL = mNasaServerPref.getText() + "?function=test_conn_nasa&user=" + mNasaServerUserPref.getText() + "&pass=" + mNasaServerPassPref.getText(); new HttpGetter(SettingsSupport.this.context, 2, SettingsSupport.this.context.getString(R.string.stChecking), mReturnHandler, true) .execute(sURL); return true; } }); if (checkUserConnPref != null) checkUserConnPref.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { String sURL = mUserServerPref.getText() + "?function=test_conn_user&user=" + mUserServerUserPref.getText() + "&pass=" + mUserServerPassPref.getText(); new HttpGetter(SettingsSupport.this.context, 1, SettingsSupport.this.context.getString(R.string.stChecking), mReturnHandler, true) .execute(sURL); return true; } }); if (checkScanConnPref != null) checkScanConnPref.setOnPreferenceClickListener(new OnPreferenceClickListener() { public boolean onPreferenceClick(Preference preference) { //String sURL = mUserServerPref.getText() + "?function=test_conn_nasa&user=" + mUserServerUserPref.getText() + "&pass=" + mUserServerPassPref.getText(); new ScanexHttpLogin(SettingsSupport.this.context, 3, SettingsSupport.this.context.getString(R.string.stChecking), mReturnHandler, true) .execute(mScanServerUserPref.getText(), mScanServerPassPref.getText()); return true; } }); }
From source file:com.citrus.mobile.RESTclient.java
public JSONObject makePostrequest() throws IOException { HttpParams redirectparams = new BasicHttpParams(); redirectparams.setParameter("http.protocol.handle-redirects", false); httpClient = new DefaultHttpClient(); HttpPost httpPost = null;//from w w w.j a v a 2 s.c o m try { httpPost = new HttpPost(urls.getString(base_url) + urls.getString(type)); httpPost.setParams(redirectparams); } catch (JSONException e) { e.printStackTrace(); } if (params != null) { List<NameValuePair> postData = new ArrayList<NameValuePair>(2); Iterator<String> iter = params.keys(); while (iter.hasNext()) { String key = iter.next(); try { String value = params.getString(key); postData.add(new BasicNameValuePair(key, value)); } catch (JSONException e) { Log.d("exception", e.toString()); } } httpPost.setEntity(new UrlEncodedFormEntity(postData)); } Iterator<String> iterhead = headers.keys(); while (iterhead.hasNext()) { String key = iterhead.next(); try { String value = headers.getString(key); httpPost.addHeader(key, value); } catch (JSONException e) { return null; } } try { response = httpClient.execute(httpPost); } catch (IOException e) { e.printStackTrace(); } return parseResponse(response); }
From source file:com.citrus.mobile.RESTclient.java
public JSONObject makePutrequest() { HttpClient client = new DefaultHttpClient(); HttpPut put = null;//w ww .j a v a2 s . c om try { put = new HttpPut(urls.getString(base_url) + urls.getString(type)); } catch (JSONException e) { e.printStackTrace(); } Iterator<String> iterhead = headers.keys(); while (iterhead.hasNext()) { String key = iterhead.next(); try { String value = headers.getString(key); put.addHeader(key, value); } catch (JSONException e) { e.printStackTrace(); } } List<NameValuePair> putdata = new ArrayList<NameValuePair>(2); Iterator<String> iter = params.keys(); while (iter.hasNext()) { String key = iter.next(); try { String value = params.getString(key); putdata.add(new BasicNameValuePair(key, value)); } catch (JSONException e) { Log.d("exception", e.toString()); } } try { put.setEntity(new UrlEncodedFormEntity(putdata)); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } try { response = client.execute(put); } catch (IOException e) { e.printStackTrace(); } return parseResponse(response); }
From source file:com.citrus.mobile.RESTclient.java
public JSONObject makePutrequest(JSONObject details) { HttpClient client = new DefaultHttpClient(); HttpPut put = null;// w w w. ja v a 2 s. c o m try { put = new HttpPut(urls.getString(base_url) + urls.getString(type)); } catch (JSONException e) { e.printStackTrace(); } Iterator<String> iterhead = headers.keys(); while (iterhead.hasNext()) { String key = iterhead.next(); try { String value = headers.getString(key); put.addHeader(key, value); } catch (JSONException e) { Log.d("exception", e.toString()); } } try { put.setEntity(new StringEntity(details.toString())); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } try { response = client.execute(put); } catch (IOException e) { e.printStackTrace(); } return parseResponse(response); }
From source file:com.asd.littleprincesbeauty.data.TaskList.java
@Override public JSONObject getCreateAction(int actionId) { JSONObject js = new JSONObject(); try {//w ww . ja v a 2 s.co m // action_type js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE, GTaskStringUtils.GTASK_JSON_ACTION_TYPE_CREATE); // action_id js.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, actionId); // index js.put(GTaskStringUtils.GTASK_JSON_INDEX, mIndex); // entity_delta JSONObject entity = new JSONObject(); entity.put(GTaskStringUtils.GTASK_JSON_NAME, getName()); entity.put(GTaskStringUtils.GTASK_JSON_CREATOR_ID, "null"); entity.put(GTaskStringUtils.GTASK_JSON_ENTITY_TYPE, GTaskStringUtils.GTASK_JSON_TYPE_GROUP); js.put(GTaskStringUtils.GTASK_JSON_ENTITY_DELTA, entity); } catch (JSONException e) { Log.e(TAG, e.toString()); e.printStackTrace(); throw new ActionFailureException("fail to generate tasklist-create jsonobject"); } return js; }
From source file:com.asd.littleprincesbeauty.data.TaskList.java
@Override public JSONObject getUpdateAction(int actionId) { JSONObject js = new JSONObject(); try {/*from w ww. j a va 2 s .c om*/ // action_type js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE, GTaskStringUtils.GTASK_JSON_ACTION_TYPE_UPDATE); // action_id js.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, actionId); // id js.put(GTaskStringUtils.GTASK_JSON_ID, getGid()); // entity_delta JSONObject entity = new JSONObject(); entity.put(GTaskStringUtils.GTASK_JSON_NAME, getName()); entity.put(GTaskStringUtils.GTASK_JSON_DELETED, getDeleted()); js.put(GTaskStringUtils.GTASK_JSON_ENTITY_DELTA, entity); } catch (JSONException e) { Log.e(TAG, e.toString()); e.printStackTrace(); throw new ActionFailureException("fail to generate tasklist-update jsonobject"); } return js; }