fix NPE
This commit is contained in:
parent
62aa49dd5b
commit
ad3794d32f
1 changed files with 7 additions and 7 deletions
|
@ -22,7 +22,7 @@ public class JsonHelper {
|
||||||
public static Object safeGetObject(JSONObject json, String fieldName, Object defaultValue) {
|
public static Object safeGetObject(JSONObject json, String fieldName, Object defaultValue) {
|
||||||
Object result = defaultValue;
|
Object result = defaultValue;
|
||||||
|
|
||||||
if (json.has(fieldName)) {
|
if (json != null && json.has(fieldName)) {
|
||||||
try {
|
try {
|
||||||
result = json.get(fieldName);
|
result = json.get(fieldName);
|
||||||
} catch (JSONException ignored) {
|
} catch (JSONException ignored) {
|
||||||
|
@ -36,7 +36,7 @@ public class JsonHelper {
|
||||||
public static String safeGetString(JSONObject json, String fieldName) {
|
public static String safeGetString(JSONObject json, String fieldName) {
|
||||||
String result = null;
|
String result = null;
|
||||||
|
|
||||||
if (json.has(fieldName)) {
|
if (json != null && json.has(fieldName)) {
|
||||||
try {
|
try {
|
||||||
result = json.getString(fieldName);
|
result = json.getString(fieldName);
|
||||||
} catch (JSONException ignored) {
|
} catch (JSONException ignored) {
|
||||||
|
@ -49,7 +49,7 @@ public class JsonHelper {
|
||||||
public static String safeGetString(JSONObject json, String fieldName, String defaultValue) {
|
public static String safeGetString(JSONObject json, String fieldName, String defaultValue) {
|
||||||
String result = defaultValue;
|
String result = defaultValue;
|
||||||
|
|
||||||
if (json.has(fieldName)) {
|
if (json != null && json.has(fieldName)) {
|
||||||
try {
|
try {
|
||||||
result = json.getString(fieldName);
|
result = json.getString(fieldName);
|
||||||
} catch (JSONException ignored) {
|
} catch (JSONException ignored) {
|
||||||
|
@ -62,7 +62,7 @@ public class JsonHelper {
|
||||||
public static double safeGetDouble(JSONObject json, String fieldName) {
|
public static double safeGetDouble(JSONObject json, String fieldName) {
|
||||||
double result = 0d;
|
double result = 0d;
|
||||||
|
|
||||||
if (json.has(fieldName)) {
|
if (json != null && json.has(fieldName)) {
|
||||||
try {
|
try {
|
||||||
result = json.getDouble(fieldName);
|
result = json.getDouble(fieldName);
|
||||||
} catch (JSONException ignored) {
|
} catch (JSONException ignored) {
|
||||||
|
@ -75,7 +75,7 @@ public class JsonHelper {
|
||||||
public static int safeGetInt(JSONObject json, String fieldName) {
|
public static int safeGetInt(JSONObject json, String fieldName) {
|
||||||
int result = 0;
|
int result = 0;
|
||||||
|
|
||||||
if (json.has(fieldName)) {
|
if (json != null && json.has(fieldName)) {
|
||||||
try {
|
try {
|
||||||
result = json.getInt(fieldName);
|
result = json.getInt(fieldName);
|
||||||
} catch (JSONException ignored) {
|
} catch (JSONException ignored) {
|
||||||
|
@ -88,7 +88,7 @@ public class JsonHelper {
|
||||||
public static long safeGetLong(JSONObject json, String fieldName) {
|
public static long safeGetLong(JSONObject json, String fieldName) {
|
||||||
long result = 0;
|
long result = 0;
|
||||||
|
|
||||||
if (json.has(fieldName)) {
|
if (json != null && json.has(fieldName)) {
|
||||||
try {
|
try {
|
||||||
result = json.getLong(fieldName);
|
result = json.getLong(fieldName);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
|
@ -101,7 +101,7 @@ public class JsonHelper {
|
||||||
public static boolean safeGetBoolean(JSONObject json, String fieldName) {
|
public static boolean safeGetBoolean(JSONObject json, String fieldName) {
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
|
|
||||||
if (json.has(fieldName)) {
|
if (json != null && json.has(fieldName)) {
|
||||||
try {
|
try {
|
||||||
result = json.getBoolean(fieldName);
|
result = json.getBoolean(fieldName);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
|
|
Loading…
Reference in a new issue