From 9df5d7e15b06109153d0499c3f1ed1a3080c94ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E6=AD=87=E5=B0=94?= Date: Tue, 23 Nov 2021 22:19:24 +0100 Subject: [PATCH] 2 new methods: isJSONObject() and isJSONArray() Check if a given input is a JSONObject or a JSONArray. --- .../com/blankj/utilcode/util/JsonUtils.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/lib/utilcode/src/main/java/com/blankj/utilcode/util/JsonUtils.java b/lib/utilcode/src/main/java/com/blankj/utilcode/util/JsonUtils.java index ea40ac3162..43046adf5a 100644 --- a/lib/utilcode/src/main/java/com/blankj/utilcode/util/JsonUtils.java +++ b/lib/utilcode/src/main/java/com/blankj/utilcode/util/JsonUtils.java @@ -26,6 +26,27 @@ private JsonUtils() { throw new UnsupportedOperationException("u can't instantiate me..."); } + + /** + * Checks if a given input is a JSONObject. + * + * @param input Anything. + * @return true if it is a JSONObject. + */ + public static boolean isJSONObject(final T input) { + return input instanceof JSONObject; + } + + /** + * Checks if a given input is a JSONArray + * + * @param input Anything. + * @return true if it is a JSONArray. + */ + public static boolean isJSONArray(final T input) { + return input instanceof JSONArray; + } + public static boolean getBoolean(final JSONObject jsonObject, final String key) { return getBoolean(jsonObject, key, false);