Code example for JSONObject

Methods: getBoolean, getInt, getString

0
        show(title, text, menuitems, multiple);
    } 
 
    private static String getSafeString(JSONObject json, String key) {
        try { 
            return json.getString(key);
        } catch (Exception e) {
            return ""; 
        } 
    } 
 
    private static JSONArray getSafeArray(JSONObject json, String key) {
        try { 
            return json.getJSONArray(key);
        } catch (Exception e) {
            return new JSONArray();
        } 
    } 
 
    private static boolean getSafeBool(JSONObject json, String key) {
        try { 
            return json.getBoolean(key);
        } catch (Exception e) {
            return false; 
        } 
    } 
 
    private static int getSafeInt(JSONObject json, String key ) {
        try { 
            return json.getInt(key);
        } catch (Exception e) {
            return 0; 
        } 
    }