This commit is contained in:
Milos Kozak 2018-10-31 07:59:04 +01:00
parent 62aa49dd5b
commit ad3794d32f

View file

@ -22,7 +22,7 @@ public class JsonHelper {
public static Object safeGetObject(JSONObject json, String fieldName, Object defaultValue) {
Object result = defaultValue;
if (json.has(fieldName)) {
if (json != null && json.has(fieldName)) {
try {
result = json.get(fieldName);
} catch (JSONException ignored) {
@ -36,7 +36,7 @@ public class JsonHelper {
public static String safeGetString(JSONObject json, String fieldName) {
String result = null;
if (json.has(fieldName)) {
if (json != null && json.has(fieldName)) {
try {
result = json.getString(fieldName);
} catch (JSONException ignored) {
@ -49,7 +49,7 @@ public class JsonHelper {
public static String safeGetString(JSONObject json, String fieldName, String defaultValue) {
String result = defaultValue;
if (json.has(fieldName)) {
if (json != null && json.has(fieldName)) {
try {
result = json.getString(fieldName);
} catch (JSONException ignored) {
@ -62,7 +62,7 @@ public class JsonHelper {
public static double safeGetDouble(JSONObject json, String fieldName) {
double result = 0d;
if (json.has(fieldName)) {
if (json != null && json.has(fieldName)) {
try {
result = json.getDouble(fieldName);
} catch (JSONException ignored) {
@ -75,7 +75,7 @@ public class JsonHelper {
public static int safeGetInt(JSONObject json, String fieldName) {
int result = 0;
if (json.has(fieldName)) {
if (json != null && json.has(fieldName)) {
try {
result = json.getInt(fieldName);
} catch (JSONException ignored) {
@ -88,7 +88,7 @@ public class JsonHelper {
public static long safeGetLong(JSONObject json, String fieldName) {
long result = 0;
if (json.has(fieldName)) {
if (json != null && json.has(fieldName)) {
try {
result = json.getLong(fieldName);
} catch (JSONException e) {
@ -101,7 +101,7 @@ public class JsonHelper {
public static boolean safeGetBoolean(JSONObject json, String fieldName) {
boolean result = false;
if (json.has(fieldName)) {
if (json != null && json.has(fieldName)) {
try {
result = json.getBoolean(fieldName);
} catch (JSONException e) {