Browse Source

Check if value is double instead of expecting exception (#3960)

* Check if value is double instead of expecting exception

* Added try catch block to compensate for React51 exception on getDouble
Malerie Pace 6 years ago
parent
commit
0519602f3f

+ 12
- 4
lib/android/app/src/main/java/com/reactnativenavigation/parse/parsers/JSONParser.java View File

69
 
69
 
70
     private static Object parseNumber(ReadableMap map, String key) {
70
     private static Object parseNumber(ReadableMap map, String key) {
71
         try {
71
         try {
72
-            return map.getInt(key);
72
+            Double doubleValue = map.getDouble(key);
73
+            if(doubleValue % 1 == 0){
74
+                return map.getInt(key);
75
+            }
76
+            return doubleValue;
73
         } catch (Exception e) {
77
         } catch (Exception e) {
74
-            return map.getDouble(key);
78
+            return map.getInt(key);
75
         }
79
         }
76
     }
80
     }
77
 
81
 
78
     private static Object parseNumber(ReadableArray arr, int index) {
82
     private static Object parseNumber(ReadableArray arr, int index) {
79
         try {
83
         try {
80
-            return arr.getInt(index);
84
+            Double doubleValue = arr.getDouble(index);
85
+            if(doubleValue % 1 == 0){
86
+                return arr.getInt(index);
87
+            }
88
+            return doubleValue;
81
         } catch (Exception e) {
89
         } catch (Exception e) {
82
-            return arr.getDouble(index);
90
+            return arr.getInt(index);
83
         }
91
         }
84
     }
92
     }
85
 }
93
 }