diff --git a/android/capacitor/src/main/java/com/getcapacitor/plugin/util/HttpRequestHandler.java b/android/capacitor/src/main/java/com/getcapacitor/plugin/util/HttpRequestHandler.java index 5077e9b85d..9d8e0a44a8 100644 --- a/android/capacitor/src/main/java/com/getcapacitor/plugin/util/HttpRequestHandler.java +++ b/android/capacitor/src/main/java/com/getcapacitor/plugin/util/HttpRequestHandler.java @@ -302,14 +302,18 @@ public static Object parseJSON(String input) throws JSONException { if ("null".equals(input.trim())) { return JSONObject.NULL; } else if ("true".equals(input.trim())) { - return new JSONObject().put("flag", "true"); + return true; } else if ("false".equals(input.trim())) { - return new JSONObject().put("flag", "false"); + return false; } else if (input.trim().length() <= 0) { return ""; } else if (input.trim().matches("^\".*\"$")) { // a string enclosed in " " is a json value, return the string without the quotes return input.trim().substring(1, input.trim().length() - 1); + } else if (input.trim().matches("^-?\\d+$")) { + return Integer.parseInt(input.trim()); + } else if (input.trim().matches("^-?\\d+(\\.\\d+)?$")) { + return Double.parseDouble(input.trim()); } else { try { return new JSObject(input); @@ -318,7 +322,7 @@ public static Object parseJSON(String input) throws JSONException { } } } catch (JSONException e) { - return new JSArray(input); + return input; } }