List of usage examples for org.json JSONException printStackTrace
public void printStackTrace()
From source file:com.extremeboredom.wordattack.utils.JSONUtils.java
/** * get JSONObject from jsonObject/*from w ww . ja v a 2s . com*/ * * @param jsonObject * @param key * @param defaultValue * @return <ul> * <li>if jsonObject is null, return defaultValue</li> * <li>if key is null or empty, return defaultValue</li> * <li>if {@link JSONObject#getJSONObject(String)} exception, return defaultValue</li> * <li>return {@link JSONObject#getJSONObject(String)}</li> * </ul> */ public static JSONObject getJSONObject(JSONObject jsonObject, String key, JSONObject defaultValue) { if (jsonObject == null || StringUtils.isEmpty(key)) { return defaultValue; } try { return jsonObject.getJSONObject(key); } catch (JSONException e) { if (isPrintException) { e.printStackTrace(); } return defaultValue; } }
From source file:com.extremeboredom.wordattack.utils.JSONUtils.java
/** * get JSONObject from jsonData//from ww w. j a v a2s .c o m * * @param jsonData * @param key * @param defaultValue * @return <ul> * <li>if jsonData is null, return defaultValue</li> * <li>if jsonData {@link JSONObject#JSONObject(String)} exception, return defaultValue</li> * <li>return {@link JSONUtils#getJSONObject(JSONObject, String, JSONObject)}</li> * </ul> */ public static JSONObject getJSONObject(String jsonData, String key, JSONObject defaultValue) { if (StringUtils.isEmpty(jsonData)) { return defaultValue; } try { JSONObject jsonObject = new JSONObject(jsonData); return getJSONObject(jsonObject, key, defaultValue); } catch (JSONException e) { if (isPrintException) { e.printStackTrace(); } return defaultValue; } }
From source file:com.extremeboredom.wordattack.utils.JSONUtils.java
/** * get JSONObject from jsonData//from w ww . j a v a 2 s . c o m * * @param jsonData * @param defaultValue * @param keyArray * @return <ul> * <li>if jsonData is null, return defaultValue</li> * <li>if keyArray is null or empty, return defaultValue</li> * <li>get {@link #getJSONObject(JSONObject, String, JSONObject)} by recursion, return it. if anyone is * null, return directly</li> * </ul> */ public static JSONObject getJSONObjectCascade(String jsonData, JSONObject defaultValue, String... keyArray) { if (StringUtils.isEmpty(jsonData)) { return defaultValue; } try { JSONObject jsonObject = new JSONObject(jsonData); return getJSONObjectCascade(jsonObject, defaultValue, keyArray); } catch (JSONException e) { if (isPrintException) { e.printStackTrace(); } return defaultValue; } }
From source file:com.extremeboredom.wordattack.utils.JSONUtils.java
/** * get JSONArray from jsonObject//from w ww. j a va 2 s . com * * @param jsonObject * @param key * @param defaultValue * @return <ul> * <li>if jsonObject is null, return defaultValue</li> * <li>if key is null or empty, return defaultValue</li> * <li>if {@link JSONObject#getJSONArray(String)} exception, return defaultValue</li> * <li>return {@link JSONObject#getJSONArray(String)}</li> * </ul> */ public static JSONArray getJSONArray(JSONObject jsonObject, String key, JSONArray defaultValue) { if (jsonObject == null || StringUtils.isEmpty(key)) { return defaultValue; } try { return jsonObject.getJSONArray(key); } catch (JSONException e) { if (isPrintException) { e.printStackTrace(); } return defaultValue; } }
From source file:com.extremeboredom.wordattack.utils.JSONUtils.java
/** * get JSONArray from jsonData/*from w w w . j a v a 2 s.c o m*/ * * @param jsonData * @param key * @param defaultValue * @return <ul> * <li>if jsonObject is null, return defaultValue</li> * <li>if jsonData {@link JSONObject#JSONObject(String)} exception, return defaultValue</li> * <li>return {@link JSONUtils#getJSONArray(JSONObject, String, JSONObject)}</li> * </ul> */ public static JSONArray getJSONArray(String jsonData, String key, JSONArray defaultValue) { if (StringUtils.isEmpty(jsonData)) { return defaultValue; } try { JSONObject jsonObject = new JSONObject(jsonData); return getJSONArray(jsonObject, key, defaultValue); } catch (JSONException e) { if (isPrintException) { e.printStackTrace(); } return defaultValue; } }
From source file:com.extremeboredom.wordattack.utils.JSONUtils.java
/** * get Boolean from jsonObject// w w w . java2s. c o m * * @param jsonObject * @param key * @param defaultValue * @return <ul> * <li>if jsonObject is null, return defaultValue</li> * <li>if key is null or empty, return defaultValue</li> * <li>return {@link JSONObject#getBoolean(String)}</li> * </ul> */ public static boolean getBoolean(JSONObject jsonObject, String key, Boolean defaultValue) { if (jsonObject == null || StringUtils.isEmpty(key)) { return defaultValue; } try { return jsonObject.getBoolean(key); } catch (JSONException e) { if (isPrintException) { e.printStackTrace(); } return defaultValue; } }
From source file:com.extremeboredom.wordattack.utils.JSONUtils.java
/** * get Boolean from jsonData// ww w . j av a2 s . c o m * * @param jsonData * @param key * @param defaultValue * @return <ul> * <li>if jsonObject is null, return defaultValue</li> * <li>if jsonData {@link JSONObject#JSONObject(String)} exception, return defaultValue</li> * <li>return {@link JSONUtils#getBoolean(JSONObject, String, Boolean)}</li> * </ul> */ public static boolean getBoolean(String jsonData, String key, Boolean defaultValue) { if (StringUtils.isEmpty(jsonData)) { return defaultValue; } try { JSONObject jsonObject = new JSONObject(jsonData); return getBoolean(jsonObject, key, defaultValue); } catch (JSONException e) { if (isPrintException) { e.printStackTrace(); } return defaultValue; } }
From source file:com.extremeboredom.wordattack.utils.JSONUtils.java
/** * get map from jsonData./*from w w w.j a v a 2s. c om*/ * * @param jsonData key-value pairs string * @param key * @return <ul> * <li>if jsonData is null, return null</li> * <li>if jsonData length is 0, return empty map</li> * <li>if jsonData {@link JSONObject#JSONObject(String)} exception, return null</li> * <li>return {@link JSONUtils#getMap(JSONObject, String)}</li> * </ul> */ public static Map<String, String> getMap(String jsonData, String key) { if (jsonData == null) { return null; } if (jsonData.length() == 0) { return new HashMap<String, String>(); } try { JSONObject jsonObject = new JSONObject(jsonData); return getMap(jsonObject, key); } catch (JSONException e) { if (isPrintException) { e.printStackTrace(); } return null; } }
From source file:com.extremeboredom.wordattack.utils.JSONUtils.java
/** * parse key-value pairs to map. ignore empty key, if getValue exception, put empty value * * @param source key-value pairs json//w w w.j av a2 s. co m * @return <ul> * <li>if source is null or source's length is 0, return empty map</li> * <li>if source {@link JSONObject#JSONObject(String)} exception, return null</li> * <li>return {@link JSONUtils#parseKeyAndValueToMap(JSONObject)}</li> * </ul> */ public static Map<String, String> parseKeyAndValueToMap(String source) { if (StringUtils.isEmpty(source)) { return null; } try { JSONObject jsonObject = new JSONObject(source); return parseKeyAndValueToMap(jsonObject); } catch (JSONException e) { if (isPrintException) { e.printStackTrace(); } return null; } }
From source file:com.example.android.popularmoviesist2.data.FetchTrailerMovieTask.java
private String[] getMoviesDataFromJson(String moviesJsonStr) throws JSONException { final String JSON_LIST = "results"; final String JSON_ID = "id"; final String JSON_KEY = "key"; final String JSON_NAME = "name"; final String JSON_SITE = "site"; urlYoutbe.clear();/*w w w. j a v a2 s . co m*/ try { JSONObject moviesJson = new JSONObject(moviesJsonStr); JSONArray moviesArray = moviesJson.getJSONArray(JSON_LIST); final String[] result = new String[moviesArray.length()]; for (int i = 0; i < moviesArray.length(); i++) { JSONObject movie = moviesArray.getJSONObject(i); String id = movie.getString(JSON_ID); String key = movie.getString(JSON_KEY); String name = movie.getString(JSON_NAME); String site = movie.getString(JSON_SITE); result[i] = key; } return result; } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); e.printStackTrace(); return null; } }