1
0
Fork 0
mirror of https://github.com/ethauvin/JSON-java.git synced 2025-06-17 07:50:52 -07:00

updates the getNumber/optNumber to not return invalid Doubles

This commit is contained in:
John J. Aylward 2017-05-18 19:49:50 -04:00
parent a7f8ff24df
commit 849b392c01
2 changed files with 54 additions and 30 deletions

View file

@ -738,7 +738,11 @@ public class JSONArray implements Iterable<Object> {
return BigInteger.valueOf(((Number) val).longValue());
}
try {
return new BigDecimal(val.toString()).toBigInteger();
final String valStr = val.toString();
if(JSONObject.isDecimalNotation(valStr)) {
return new BigDecimal(valStr).toBigInteger();
}
return new BigInteger(valStr);
} catch (Exception e) {
return defaultValue;
}