All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.cocoahero.android.geojson.util.JSONUtils Maven / Gradle / Ivy

There is a newer version: 9.2.1
Show newest version
package com.cocoahero.android.geojson.util;

import org.json.JSONArray;
import org.json.JSONObject;

public class JSONUtils {

    public static boolean isEmpty(JSONObject json) {
        return (json == null) || (json.length() <= 0);
    }

    public static boolean isEmpty(JSONArray json) {
        return (json == null) || (json.length() <= 0);
    }

    public static String optString(JSONObject json, String name) {
        return optString(json, name, null);
    }

    public static String optString(JSONObject json, String name, String fallback) {
        if (json != null) {
            if (!json.isNull(name)) {
                return json.optString(name, fallback);
            }
            return fallback;
        }
        return null;
    }

    public static String optString(JSONArray json, int index) {
        return optString(json, index, null);
    }

    public static String optString(JSONArray json, int index, String fallback) {
        if (json != null) {
            if (!json.isNull(index)) {
                return json.optString(index, fallback);
            }
            return fallback;
        }
        return null;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy