From cb7a04ff0948a1e657b33d8f6fb0eec8032904d7 Mon Sep 17 00:00:00 2001 From: juntao Date: Sun, 12 Sep 2021 17:24:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=95=BF=E6=8C=89=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E6=A0=87=E7=AD=BE=E4=B8=8D=E8=83=BD=E4=BF=9D=E5=AD=98?= =?UTF-8?q?=E9=83=A8=E5=88=86=E9=A1=B5=E9=9D=A2=E5=BF=AB=E6=8D=B7=E8=B7=B3?= =?UTF-8?q?=E8=BD=AC=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/gh/common/util/EntranceUtils.java | 45 ++++++++++--------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/com/gh/common/util/EntranceUtils.java b/app/src/main/java/com/gh/common/util/EntranceUtils.java index 9348ce7b22..8c9bf8f828 100644 --- a/app/src/main/java/com/gh/common/util/EntranceUtils.java +++ b/app/src/main/java/com/gh/common/util/EntranceUtils.java @@ -330,38 +330,41 @@ public class EntranceUtils { /** * 将 Bundle 转为 Json */ - private static JSONObject getJsonFromBundle(Bundle bundle, JSONObject json, @Nullable JSONObject bundleWrapper) { + private static JSONObject getJsonFromBundle(Bundle bundle, JSONObject json, @Nullable JSONObject bundleWrapper) throws JSONException { Set keys = bundle.keySet(); for (String key : keys) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - try { - Object object = bundle.get(key); - if (object instanceof Bundle) { - json = getJsonFromBundle((Bundle) object, json, new JSONObject()); - } else if (object instanceof Parcelable) { - String parcelableName = key + ":parcelable"; - String parcelableType = object.getClass().getName(); - String objectJsonString = GsonUtils.toJson(object); - JSONObject jObject = null; - jObject = new JSONObject(objectJsonString); + Object object = bundle.get(key); + if (object instanceof Bundle) { + json = getJsonFromBundle((Bundle) object, json, new JSONObject()); + } else if (object instanceof Parcelable) { + String parcelableName = key + ":parcelable"; + String parcelableType = object.getClass().getName(); + String objectJsonString = GsonUtils.toJson(object); + JSONObject jObject = null; + jObject = new JSONObject(objectJsonString); - if (bundleWrapper != null) { - bundleWrapper.put(parcelableName, parcelableType); - bundleWrapper.put(key, jObject); - json.put(":bundle", bundleWrapper); - } else { - json.put(parcelableName, parcelableType); - json.put(key, jObject); - } + if (bundleWrapper != null) { + bundleWrapper.put(parcelableName, parcelableType); + bundleWrapper.put(key, jObject); + } else { + json.put(parcelableName, parcelableType); + json.put(key, jObject); + } + } else { + if (bundleWrapper != null) { + bundleWrapper.put(key, JSONObject.wrap(bundle.get(key))); } else { json.put(key, JSONObject.wrap(bundle.get(key))); } - } catch (JSONException e) { - e.printStackTrace(); } } } + + if (bundleWrapper != null) { + json.put(":bundle", bundleWrapper); + } return json; }