Example usage for org.json JSONException printStackTrace

List of usage examples for org.json JSONException printStackTrace

Introduction

In this page you can find the example usage for org.json JSONException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:com.extremeboredom.wordattack.utils.JSONUtils.java

/**
 * get Int from jsonObject/* ww  w. j  a  va2s .  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>if {@link JSONObject#getInt(String)} exception, return defaultValue</li>
 * <li>return {@link JSONObject#getInt(String)}</li>
 * </ul>
 */
public static Integer getInt(JSONObject jsonObject, String key, Integer defaultValue) {
    if (jsonObject == null || StringUtils.isEmpty(key)) {
        return defaultValue;
    }

    try {
        return jsonObject.getInt(key);
    } catch (JSONException e) {
        if (isPrintException) {
            e.printStackTrace();
        }
        return defaultValue;
    }
}

From source file:com.extremeboredom.wordattack.utils.JSONUtils.java

/**
 * get Int from jsonData//  www .  j a  va2 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#getInt(JSONObject, String, Integer)}</li>
 * </ul>
 */
public static Integer getInt(String jsonData, String key, Integer defaultValue) {
    if (StringUtils.isEmpty(jsonData)) {
        return defaultValue;
    }

    try {
        JSONObject jsonObject = new JSONObject(jsonData);
        return getInt(jsonObject, key, defaultValue);
    } catch (JSONException e) {
        if (isPrintException) {
            e.printStackTrace();
        }
        return defaultValue;
    }
}

From source file:com.extremeboredom.wordattack.utils.JSONUtils.java

/**
 * get Double from jsonObject//  w  ww .  ja va 2 s .  c  om
 *
 * @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#getDouble(String)} exception, return defaultValue</li>
 * <li>return {@link JSONObject#getDouble(String)}</li>
 * </ul>
 */
public static Double getDouble(JSONObject jsonObject, String key, Double defaultValue) {
    if (jsonObject == null || StringUtils.isEmpty(key)) {
        return defaultValue;
    }

    try {
        return jsonObject.getDouble(key);
    } catch (JSONException e) {
        if (isPrintException) {
            e.printStackTrace();
        }
        return defaultValue;
    }
}

From source file:com.extremeboredom.wordattack.utils.JSONUtils.java

/**
 * get Double from jsonData//from w  ww. j a  va  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#getDouble(JSONObject, String, Double)}</li>
 * </ul>
 */
public static Double getDouble(String jsonData, String key, Double defaultValue) {
    if (StringUtils.isEmpty(jsonData)) {
        return defaultValue;
    }

    try {
        JSONObject jsonObject = new JSONObject(jsonData);
        return getDouble(jsonObject, key, defaultValue);
    } catch (JSONException e) {
        if (isPrintException) {
            e.printStackTrace();
        }
        return defaultValue;
    }
}

From source file:com.extremeboredom.wordattack.utils.JSONUtils.java

/**
 * get String from jsonObject//  w ww  .j  a v a  2 s .  c  om
 *
 * @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#getString(String)} exception, return defaultValue</li>
 * <li>return {@link JSONObject#getString(String)}</li>
 * </ul>
 */
public static String getString(JSONObject jsonObject, String key, String defaultValue) {
    if (jsonObject == null || StringUtils.isEmpty(key)) {
        return defaultValue;
    }

    try {
        return jsonObject.getString(key);
    } catch (JSONException e) {
        if (isPrintException) {
            e.printStackTrace();
        }
        return defaultValue;
    }
}

From source file:com.extremeboredom.wordattack.utils.JSONUtils.java

/**
 * get String from jsonData//  ww w .j  a v 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#getString(JSONObject, String, String)}</li>
 * </ul>
 */
public static String getString(String jsonData, String key, String defaultValue) {
    if (StringUtils.isEmpty(jsonData)) {
        return defaultValue;
    }

    try {
        JSONObject jsonObject = new JSONObject(jsonData);
        return getString(jsonObject, key, defaultValue);
    } catch (JSONException e) {
        if (isPrintException) {
            e.printStackTrace();
        }
        return defaultValue;
    }
}

From source file:com.extremeboredom.wordattack.utils.JSONUtils.java

/**
 * get String array from jsonObject//w ww.j  a  v a 2  s.  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>if {@link JSONObject#getJSONArray(String)} exception, return defaultValue</li>
 * <li>if {@link JSONArray#getString(int)} exception, return defaultValue</li>
 * <li>return string array</li>
 * </ul>
 */
public static String[] getStringArray(JSONObject jsonObject, String key, String[] defaultValue) {
    if (jsonObject == null || StringUtils.isEmpty(key)) {
        return defaultValue;
    }

    try {
        JSONArray statusArray = jsonObject.getJSONArray(key);
        if (statusArray != null) {
            String[] value = new String[statusArray.length()];
            for (int i = 0; i < statusArray.length(); i++) {
                value[i] = statusArray.getString(i);
            }
            return value;
        }
    } catch (JSONException e) {
        if (isPrintException) {
            e.printStackTrace();
        }
        return defaultValue;
    }
    return defaultValue;
}

From source file:com.extremeboredom.wordattack.utils.JSONUtils.java

/**
 * get String array from jsonData/*  w w w .j ava  2  s  . co  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#getStringArray(JSONObject, String, String[])}</li>
 * </ul>
 */
public static String[] getStringArray(String jsonData, String key, String[] defaultValue) {
    if (StringUtils.isEmpty(jsonData)) {
        return defaultValue;
    }

    try {
        JSONObject jsonObject = new JSONObject(jsonData);
        return getStringArray(jsonObject, key, defaultValue);
    } catch (JSONException e) {
        if (isPrintException) {
            e.printStackTrace();
        }
        return defaultValue;
    }
}

From source file:com.extremeboredom.wordattack.utils.JSONUtils.java

/**
 * get String list from jsonObject//from  www  . ja  v a2 s.co  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>if {@link JSONObject#getJSONArray(String)} exception, return defaultValue</li>
 * <li>if {@link JSONArray#getString(int)} exception, return defaultValue</li>
 * <li>return string array</li>
 * </ul>
 */
public static List<String> getStringList(JSONObject jsonObject, String key, List<String> defaultValue) {
    if (jsonObject == null || StringUtils.isEmpty(key)) {
        return defaultValue;
    }

    try {
        JSONArray statusArray = jsonObject.getJSONArray(key);
        if (statusArray != null) {
            List<String> list = new ArrayList<String>();
            for (int i = 0; i < statusArray.length(); i++) {
                list.add(statusArray.getString(i));
            }
            return list;
        }
    } catch (JSONException e) {
        if (isPrintException) {
            e.printStackTrace();
        }
        return defaultValue;
    }
    return defaultValue;
}

From source file:com.extremeboredom.wordattack.utils.JSONUtils.java

/**
 * get String list from jsonData/* ww  w  .  j  a  v a  2s  . 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#getStringList(JSONObject, String, List)}</li>
 * </ul>
 */
public static List<String> getStringList(String jsonData, String key, List<String> defaultValue) {
    if (StringUtils.isEmpty(jsonData)) {
        return defaultValue;
    }

    try {
        JSONObject jsonObject = new JSONObject(jsonData);
        return getStringList(jsonObject, key, defaultValue);
    } catch (JSONException e) {
        if (isPrintException) {
            e.printStackTrace();
        }
        return defaultValue;
    }
}