Skip to content

Commit 07b2d65

Browse files
author
John J. Aylward
committed
Fixes stleary#187 -0 now returns as a double.
1 parent 5b67330 commit 07b2d65

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

JSONObject.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ of this software and associated documentation files (the "Software"), to deal
3030
import java.lang.reflect.Field;
3131
import java.lang.reflect.Method;
3232
import java.lang.reflect.Modifier;
33-
import java.math.*;
33+
import java.math.BigDecimal;
34+
import java.math.BigInteger;
3435
import java.util.Collection;
3536
import java.util.Enumeration;
3637
import java.util.HashMap;
@@ -1500,19 +1501,19 @@ public static Object stringToValue(String string) {
15001501
if ((b >= '0' && b <= '9') || b == '-') {
15011502
try {
15021503
if (string.indexOf('.') > -1 || string.indexOf('e') > -1
1503-
|| string.indexOf('E') > -1) {
1504+
|| string.indexOf('E') > -1
1505+
|| "0".equals(string.substring(1))) {
15041506
d = Double.valueOf(string);
15051507
if (!d.isInfinite() && !d.isNaN()) {
15061508
return d;
15071509
}
15081510
} else {
15091511
Long myLong = new Long(string);
15101512
if (string.equals(myLong.toString())) {
1511-
if (myLong == myLong.intValue()) {
1512-
return myLong.intValue();
1513-
} else {
1514-
return myLong;
1513+
if (myLong.longValue() == myLong.intValue()) {
1514+
return Integer.valueOf(myLong.intValue());
15151515
}
1516+
return myLong;
15161517
}
15171518
}
15181519
} catch (Exception ignore) {

0 commit comments

Comments
 (0)