Skip to content

Commit f6ceb0f

Browse files
authored
Merge pull request Blankj#1571 from NotNotMarshall/patch-7
2 new methods: isJSONObject() and isJSONArray()
2 parents caafcd6 + 9df5d7e commit f6ceb0f

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

lib/utilcode/src/main/java/com/blankj/utilcode/util/JsonUtils.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,27 @@ private JsonUtils() {
2626
throw new UnsupportedOperationException("u can't instantiate me...");
2727
}
2828

29+
30+
/**
31+
* Checks if a given input is a JSONObject.
32+
*
33+
* @param input Anything.
34+
* @return true if it is a JSONObject.
35+
*/
36+
public static <T> boolean isJSONObject(final T input) {
37+
return input instanceof JSONObject;
38+
}
39+
40+
/**
41+
* Checks if a given input is a JSONArray
42+
*
43+
* @param input Anything.
44+
* @return true if it is a JSONArray.
45+
*/
46+
public static <T> boolean isJSONArray(final T input) {
47+
return input instanceof JSONArray;
48+
}
49+
2950
public static boolean getBoolean(final JSONObject jsonObject,
3051
final String key) {
3152
return getBoolean(jsonObject, key, false);

0 commit comments

Comments
 (0)