List of usage examples for org.json JSONException getMessage
public String getMessage()
From source file:es.rocapal.wtl.api.WTLManager.java
private Response parseResponse(String jsonResponse) { JSONObject json;//ww w .j a v a 2 s .com if (jsonResponse == null) return null; try { json = new JSONObject(jsonResponse); if (json.has(CODE_KEY) && json.has(MSG_KEY)) return new Response(json.getInt(CODE_KEY), json.getString(MSG_KEY)); else return null; } catch (JSONException e) { Log.e(TAG, e.getMessage()); return null; } }
From source file:org.eldslott.armory.utils.JsonUtils.java
public static Integer getInt(JSONObject jsonObject, String name) { try {//from w w w.j a v a 2 s . c o m return Integer.parseInt((String) jsonObject.get(name)); } catch (JSONException e) { Log.e(JsonUtils.class.toString(), "could not get from jsonObject for name '" + name + "': " + e.getMessage()); } catch (Exception e) { Log.e(JsonUtils.class.toString(), "could not parse int for name " + name + "': " + e.getMessage()); try { Log.e(JsonUtils.class.toString(), "value of unparseable int was: " + jsonObject.get(name)); } catch (Exception e2) { Log.e(JsonUtils.class.toString(), "could not get unparseable int value from jsonObject: " + e2.getMessage()); } } return null; }
From source file:org.eldslott.armory.utils.JsonUtils.java
public static Double getDouble(JSONObject jsonObject, String name) { try {/*from w w w .j a v a2 s . c om*/ return Double.parseDouble((String) jsonObject.get(name)); } catch (JSONException e) { Log.e(JsonUtils.class.toString(), "could not get from jsonObject for name '" + name + "': " + e.getMessage()); } catch (Exception e) { Log.e(JsonUtils.class.toString(), "could not parse double for name " + name + "': " + e.getMessage()); try { Log.e(JsonUtils.class.toString(), "value of unparseable double was: " + jsonObject.get(name)); } catch (Exception e2) { Log.e(JsonUtils.class.toString(), "could not get unparseable double value from jsonObject: " + e2.getMessage()); } } return null; }
From source file:org.eldslott.armory.utils.JsonUtils.java
public static String getString(JSONObject jsonObject, String name) { try {//from ww w . j a v a2s . com return String.valueOf(jsonObject.get(name)); } catch (JSONException e) { Log.e(JsonUtils.class.toString(), "could not get from jsonObject for name '" + name + "': " + e.getMessage()); } catch (Exception e) { Log.e(JsonUtils.class.toString(), "could not get from jsonObject for name '" + name + "': " + e.getMessage()); } return null; }
From source file:org.araqne.confdb.file.Importer.java
public void importData(InputStream is) throws IOException, ParseException { if (is == null) throw new IllegalArgumentException("import input stream cannot be null"); logger.debug("araqne confdb: start import data"); db.lock();/*w ww .j av a 2 s. co m*/ try { JSONTokener t = new JSONTokener(new InputStreamReader(is, Charset.forName("utf-8"))); Map<String, Object> metadata = parseMetadata(t); Integer version = (Integer) metadata.get("version"); if (version != 1) throw new ParseException("unsupported confdb data format version: " + version, -1); Manifest manifest = db.getManifest(null); List<ConfigChange> configChanges = new ArrayList<ConfigChange>(); char comma = t.nextClean(); if (comma == ',') parseCollections(t, manifest, configChanges); writeManifestLog(manifest); writeChangeLog(configChanges, manifest.getId()); logger.debug("araqne confdb: import complete"); } catch (JSONException e) { throw new ParseException(e.getMessage(), 0); } finally { db.unlock(); } }
From source file:com.df.kia.carCheck.VehicleInfoLayout.java
/** * ???//from w w w . ja v a 2 s . c om */ private void getCarSettingsFromServer(String seriesId) { GetCarSettingsTask mGetCarSettingsTask = new GetCarSettingsTask(rootView.getContext(), seriesId, new GetCarSettingsTask.OnGetCarSettingsFinished() { @Override public void onFinished(String result) { try { JSONObject jsonObject = new JSONObject(result); updateCarSettings(jsonObject.getString("config"), jsonObject.getString("category"), jsonObject.getString("figure")); // UI updateUi(); } catch (JSONException e) { Log.d("DFCarChecker", "Json?" + e.getMessage()); } } @Override public void onFailed(String result) { // ?? Log.d("DFCarChecker", "???" + result); Toast.makeText(rootView.getContext(), result, Toast.LENGTH_LONG).show(); } }); mGetCarSettingsTask.execute(); }
From source file:com.example.android.popularmoviesist2.data.FetchDetailMovieTask.java
private String[] getMoviesDataFromJson(String moviesJsonStr) throws JSONException { final String JSON_LIST = "results"; final String JSON_AUTHOR = "author"; final String JSON_CONTENT = "content"; final String[] result = new String[2]; try {/* w w w . j av a 2 s . c om*/ JSONObject moviesJson = new JSONObject(moviesJsonStr); JSONArray moviesArray = moviesJson.getJSONArray(JSON_LIST); for (int i = 0; i < moviesArray.length(); i++) { JSONObject movie = moviesArray.getJSONObject(i); String author = movie.getString(JSON_AUTHOR); String content = movie.getString(JSON_CONTENT); result[0] = author; result[1] = content; } return result; } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); e.printStackTrace(); return null; } }
From source file:com.example.android.popularmoviesist2.data.FetchDetailMovieTask.java
@Override protected String[] doInBackground(String... params) { HttpURLConnection urlConnection = null; BufferedReader reader = null; movieId = params[0];// www . j a va2s .c o m String moviesJsonStr = null; final String MOVIE_REVIEW_URL = "http://api.themoviedb.org/3/movie/" + movieId + "/reviews"; final String APIKEY_PARAM = "api_key"; try { Uri builtUri = Uri.parse(MOVIE_REVIEW_URL).buildUpon() .appendQueryParameter(APIKEY_PARAM, BuildConfig.OPEN_TMDB_MAP_API_KEY).build(); URL url = new URL(builtUri.toString()); urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setRequestMethod("GET"); urlConnection.connect(); // Read the input stream into a String InputStream inputStream = urlConnection.getInputStream(); StringBuffer buffer = new StringBuffer(); if (inputStream == null) { return null; } reader = new BufferedReader(new InputStreamReader(inputStream)); String line; while ((line = reader.readLine()) != null) { buffer.append(line + "\n"); } if (buffer.length() == 0) { return null; } moviesJsonStr = buffer.toString(); //Log.v(LOG_TAG, "Movies string: " + moviesJsonStr); return getMoviesDataFromJson(moviesJsonStr); } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); e.printStackTrace(); } catch (IOException e) { Log.e(LOG_TAG, "Error ", e); return null; } finally { if (urlConnection != null) { urlConnection.disconnect(); } if (reader != null) { try { reader.close(); } catch (final IOException e) { Log.e(LOG_TAG, "Error closing stream", e); } } } return null; }
From source file:com.nicolacimmino.expensestracker.tracker.expenses_api.ExpensesApiGenerateAuthTokenRequest.java
public String getAuthToken() { try {/*w w w. j av a2 s .c o m*/ if (jsonResponseObject != null) { return jsonResponseObject.getString("auth_token"); } } catch (JSONException e) { Log.e(TAG, "Invalid response: " + e.getMessage()); } return null; }
From source file:org.spiffyui.server.AuthServlet.java
@Override public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType(CONTENT_TYPE); String auth = null;//from w w w . ja v a 2 s . co m /* * We are manually reading the request as bytes and * then converting it to characters. This is extra * work and we should be able to just call getReader * insted of getInputStream. However, the JBoss * implementation of the reader here has a bug that * sometiems shows up where the index of the reader * is wrong so we can work around it using the input * stream directly. * * https://jira.jboss.org/browse/JBAS-7817 */ InputStream in = request.getInputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream(); int read; byte[] buf = new byte[1024]; try { while ((read = in.read(buf)) > 0) { out.write(buf, 0, read); } } finally { if (in != null) { in.close(); } } if (request.getCharacterEncoding() != null) { auth = out.toString(request.getCharacterEncoding()); } else { /* * There are some cases where the requested character encoding is null. * This happens with some application servers and with IE7. We need to * use some encoding in that case so we just use UTF-8. */ auth = out.toString("UTF-8"); } try { JSONObject authObj = new JSONObject(auth); if (request.getMethod().equals("POST")) { doLogin(request, response, authObj.getString(RESTAuthConstants.USERNAME_TOKEN), authObj.getString(RESTAuthConstants.PASSWORD_TOKEN), authObj.getString(RESTAuthConstants.AUTH_URL_TOKEN), authObj.getString(RESTAuthConstants.AUTH_LOGOUT_URL_TOKEN)); return; } else if (request.getMethod().equals("DELETE")) { doLogout(request, response, authObj.getString(RESTAuthConstants.USER_TOKEN), authObj.getString(RESTAuthConstants.AUTH_URL_TOKEN)); return; } } catch (JSONException e) { LOGGER.throwing(AuthServlet.class.getName(), "service", e); returnError(response, e.getMessage(), RESTAuthConstants.INVALID_JSON); } }