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; }