public static JSONObject convertReadableMapToJsonObject()

in appcenter-analytics/android/src/main/java/com/microsoft/appcenter/reactnative/analytics/ReactNativeUtils.java [19:54]


    public static JSONObject convertReadableMapToJsonObject(ReadableMap map) throws JSONException {
        JSONObject jsonObj = new JSONObject();
        ReadableMapKeySetIterator it = map.keySetIterator();
        while (it.hasNextKey()) {
            String key = it.nextKey();
            ReadableType type = map.getType(key);
            switch (type) {
                case Map:
                    jsonObj.put(key, convertReadableMapToJsonObject(map.getMap(key)));
                    break;
                case Array:
                    jsonObj.put(key, convertReadableArrayToJsonArray(map.getArray(key)));
                    break;
                case String:
                    jsonObj.put(key, map.getString(key));
                    break;
                case Number:
                    Double number = map.getDouble(key);
                    if ((number == Math.floor(number)) && !Double.isInfinite(number)) {
                        jsonObj.put(key, number.longValue());
                    } else {
                        jsonObj.put(key, number.doubleValue());
                    }

                    break;
                case Boolean:
                    jsonObj.put(key, map.getBoolean(key));
                    break;
                default:
                    jsonObj.put(key, null);
                    break;
            }
        }

        return jsonObj;
    }