List of usage examples for org.json JSONException printStackTrace
public void printStackTrace()
From source file:nl.hnogames.domoticzapi.Parsers.DevicesParser.java
@Override public void parseResult(String result) { try {/* w w w .j av a 2s . com*/ JSONArray jsonArray = new JSONArray(result); ArrayList<DevicesInfo> mDevices = new ArrayList<>(); if (jsonArray.length() > 0) { for (int i = 0; i < jsonArray.length(); i++) { JSONObject row = jsonArray.getJSONObject(i); mDevices.add(new DevicesInfo(row)); } } if (idx == 999999) receiver.onReceiveDevices(mDevices); else { receiver.onReceiveDevice(getDevice(idx, mDevices, scene_or_group)); } } catch (JSONException e) { Log.e(TAG, "DevicesParser JSON exception"); e.printStackTrace(); receiver.onError(e); } }
From source file:com.ibm.mobilefirst.mobileedge.abstractmodel.BarometerData.java
@Override public JSONObject asJSON() { JSONObject json = super.asJSON(); try {/*from w w w.j a v a 2 s . co m*/ JSONObject data = new JSONObject(); data.put("temperature", temperature); data.put("airPressure", airPressure); json.put("barometer", data); } catch (JSONException e) { e.printStackTrace(); } return json; }
From source file:com.phonegap.Storage.java
/** * Process query results./*from w w w . j av a 2s . c om*/ * * @param cur Cursor into query results * @param tx_id Transaction id */ public void processResults(Cursor cur, String tx_id) { String result = "[]"; // If query result has rows if (cur.moveToFirst()) { JSONArray fullresult = new JSONArray(); String key = ""; String value = ""; int colCount = cur.getColumnCount(); // Build up JSON result object for each row do { JSONObject row = new JSONObject(); try { for (int i = 0; i < colCount; ++i) { key = cur.getColumnName(i); value = cur.getString(i); row.put(key, value); } fullresult.put(row); } catch (JSONException e) { e.printStackTrace(); } } while (cur.moveToNext()); result = fullresult.toString(); } // Let JavaScript know that there are no more rows this.sendJavascript("droiddb.completeQuery('" + tx_id + "', " + result + ");"); }
From source file:com.rsimiao.exemplosloopj.UsuarioWS.java
public void buscar(final Handler handler) { try {/*from ww w. j ava 2 s.com*/ RequestParams parametros = new RequestParams(); parametros.add("limite", "todos"); Wscliente.post(url, parametros, new AsyncHttpResponseHandler() { @Override public void onFailure(int code, Header[] header, byte[] conteudo, Throwable arg3) { //voc pode colocar aqui seu tratamento de erro Log.d("WS USUARIO", "DEU ERRO"); Message msg = new Message(); msg.what = 0; //defino um identificador para a msg coloco 1 para sucesso e 0 para erro. handler.sendMessage(msg); } @Override public void onSuccess(int code, Header[] header, byte[] conteudo) { try { JSONObject json = new JSONObject(new String(conteudo)); List<Usuario> usuarios = new ArrayList<Usuario>(); //sua lgica para tratar o json recebido (no precisa ser desse modo jurstico) if (json.has("status") && json.getString("status").equalsIgnoreCase("success")) { JSONArray jUsrs = json.getJSONArray("usuarios"); for (int i = 0; i < jUsrs.length(); i++) { Usuario u = new Usuario(); u.setNome(jUsrs.getJSONObject(i).getString("nome")); u.setUsuario(jUsrs.getJSONObject(i).getString("usuario")); u.setLogged(jUsrs.getJSONObject(i).getBoolean("islogged")); usuarios.add(u); } Message msg = new Message(); msg.what = 1; //defino um identificador para a msg coloco 1 para sucesso e 0 para erro. msg.obj = usuarios; handler.sendMessage(msg); } } catch (JSONException e) { e.printStackTrace(); } } }); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.phelps.liteweibo.model.weibo.User.java
public static User parse(String jsonString) { try {/*from www .j a v a 2 s . c o m*/ JSONObject jsonObject = new JSONObject(jsonString); return User.parse(jsonObject); } catch (JSONException e) { e.printStackTrace(); } return null; }
From source file:com.ecofactor.qa.automation.newapp.service.MockDataServiceImpl.java
/** * Gets the job data./*from ww w. ja va2 s. co m*/ * * @param thermostatId * the thermostat id * @return the job data * @see com.ecofactor.qa.automation.algorithm.service.DataService#getJobData(java.lang.Integer) */ @Override public JSONArray getJobData(Integer thermostatId) { if (jobData == null) { log("Get json Array for Thermostat Id : " + thermostatId, true); Thermostat thermostat = findBythermostatId(thermostatId); jobDataList = mockJobDataBuilder.build(testName, thermostat.getTimezone()); jobData = new JSONArray(); int i = 0; for (MockJobData mockJobData : jobDataList) { try { JSONObject jsonObject = new JSONObject(); jsonObject.put("start", DateUtil.format(mockJobData.getStart(), "HH:mm:ss")); jsonObject.put("end", DateUtil.format(mockJobData.getEnd(), "HH:mm:ss")); jsonObject.put("moBlackOut", mockJobData.getBlackout()); Calendar cuttOffTime = (Calendar) Calendar .getInstance(TimeZone.getTimeZone(thermostat.getTimezone())).clone(); cuttOffTime.set(Calendar.HOUR_OF_DAY, 0); cuttOffTime.set(Calendar.MINUTE, 0); cuttOffTime.set(Calendar.SECOND, 0); if (mockJobData.getCutoff() == null) { jsonObject.put("moCutoff", DateUtil.format(cuttOffTime, "HH:mm:ss")); } else { jsonObject.put("moCutoff", mockJobData.getCutoff()); } jsonObject.put("moRecovery", mockJobData.getRecovery()); jsonObject.put("deltaEE", mockJobData.getDelta()); jobData.put(i, jsonObject); } catch (JSONException e) { e.printStackTrace(); } i++; } log("Json Array : " + jobData, true); DataUtil.printMockSPOJobDataJson(jobData); } return jobData; }
From source file:com.ecofactor.qa.automation.newapp.service.MockDataServiceImpl.java
/** * Checks if is sPO block active.//from w ww .j ava2 s . c o m * * @param thermostatId * the thermostat id * @param algoId * the algo id * @return true, if is sPO block active * @see com.ecofactor.qa.automation.algorithm.service.DataService#isSPOBlockActive(java.lang.Integer, * int) */ @Override public boolean isSPOBlockActive(Integer thermostatId, int algoId) { log("Check if SPO is active for thermostat :" + thermostatId, true); boolean spoActive = false; Thermostat thermostat = findBythermostatId(thermostatId); Calendar currentTime = (Calendar) Calendar.getInstance(TimeZone.getTimeZone(thermostat.getTimezone())) .clone(); JSONArray jsonArray = getJobData(thermostatId); for (int i = 0; i < jsonArray.length(); i++) { try { JSONObject jsonObj = jsonArray.getJSONObject(i); Calendar startCal = DateUtil.getTimeZoneCalendar((String) jsonObj.get("start"), thermostat.getTimezone()); Calendar endcal = DateUtil.getTimeZoneCalendar((String) jsonObj.get("end"), thermostat.getTimezone()); if (currentTime.after(startCal) && currentTime.before(endcal)) { spoActive = true; break; } } catch (JSONException e) { e.printStackTrace(); } } return spoActive; }
From source file:com.tweetlanes.android.App.java
public void updateTwitterAccountCount() { mAccounts.clear();/*ww w .j a v a2 s . c o m*/ long currentAccountId = mPreferences.getLong(SHARED_PREFERENCES_KEY_CURRENT_ACCOUNT_ID, -1); String accountIndices = mPreferences.getString(SHARED_PREFERENCES_KEY_ACCOUNT_INDICES, null); if (accountIndices != null) { try { JSONArray jsonArray = new JSONArray(accountIndices); for (int i = 0; i < jsonArray.length(); i++) { Long id = jsonArray.getLong(i); String key = getAccountDescriptorKey(id); String jsonAsString = mPreferences.getString(key, null); if (jsonAsString != null) { AccountDescriptor account = new AccountDescriptor(this, jsonAsString); mAccounts.add(account); if (currentAccountId != -1 && account.getId() == currentAccountId) { mCurrentAccountIndex = i; } } } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (mCurrentAccountIndex == null && mAccounts.size() > 0) { mCurrentAccountIndex = 0; } }
From source file:com.tweetlanes.android.App.java
public void onPostSignIn(TwitterUser user, String oAuthToken, String oAuthSecret, SocialNetConstant.Type oSocialNetType) { if (user != null) { try {/*from w w w .ja v a 2s. c o m*/ final Editor edit = mPreferences.edit(); String userIdAsString = Long.toString(user.getId()); AccountDescriptor account = new AccountDescriptor(this, user, oAuthToken, oAuthSecret, oSocialNetType); edit.putString(getAccountDescriptorKey(user.getId()), account.toString()); String accountIndices = mPreferences.getString(SHARED_PREFERENCES_KEY_ACCOUNT_INDICES, null); JSONArray jsonArray; if (accountIndices == null) { jsonArray = new JSONArray(); jsonArray.put(0, user.getId()); mAccounts.add(account); } else { jsonArray = new JSONArray(accountIndices); boolean exists = false; for (int i = 0; i < jsonArray.length(); i++) { String c = jsonArray.getString(i); if (c.compareTo(userIdAsString) == 0) { exists = true; mAccounts.set(i, account); break; } } if (exists == false) { jsonArray.put(userIdAsString); mAccounts.add(account); } } accountIndices = jsonArray.toString(); edit.putString(SHARED_PREFERENCES_KEY_ACCOUNT_INDICES, accountIndices); edit.commit(); setCurrentAccount(user.getId()); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } updateTwitterAccountCount(); if (TwitterManager.get().getSocialNetType() == oSocialNetType) { TwitterManager.get().setOAuthTokenWithSecret(oAuthToken, oAuthSecret, true); } else { TwitterManager.initModule(oSocialNetType, oSocialNetType == SocialNetConstant.Type.Twitter ? ConsumerKeyConstants.TWITTER_CONSUMER_KEY : ConsumerKeyConstants.APPDOTNET_CONSUMER_KEY, oSocialNetType == SocialNetConstant.Type.Twitter ? ConsumerKeyConstants.TWITTER_CONSUMER_SECRET : ConsumerKeyConstants.APPDOTNET_CONSUMER_SECRET, oAuthToken, oAuthSecret, getCurrentAccountKey(), mConnectionStatusCallbacks); } } }
From source file:de.dakror.virtualhub.data.Catalog.java
public Catalog(JSONObject o) { try {/*from w w w. ja v a 2 s . com*/ name = o.getString("name"); JSONArray sources = o.getJSONArray("sources"); for (int i = 0; i < sources.length(); i++) this.sources.add(new File(sources.getString(i))); JSONArray tags = o.getJSONArray("tags"); for (int i = 0; i < tags.length(); i++) this.tags.add(tags.getString(i)); } catch (JSONException e) { e.printStackTrace(); } }