mirror of
https://github.com/ethauvin/JSON-java.git
synced 2025-06-17 07:50:52 -07:00
Fixes #187 -0 now returns as a double.
This commit is contained in:
parent
5b67330b71
commit
07b2d65e30
1 changed files with 7 additions and 6 deletions
|
@ -30,7 +30,8 @@ import java.io.Writer;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
import java.math.*;
|
import java.math.BigDecimal;
|
||||||
|
import java.math.BigInteger;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -1500,7 +1501,8 @@ public class JSONObject {
|
||||||
if ((b >= '0' && b <= '9') || b == '-') {
|
if ((b >= '0' && b <= '9') || b == '-') {
|
||||||
try {
|
try {
|
||||||
if (string.indexOf('.') > -1 || string.indexOf('e') > -1
|
if (string.indexOf('.') > -1 || string.indexOf('e') > -1
|
||||||
|| string.indexOf('E') > -1) {
|
|| string.indexOf('E') > -1
|
||||||
|
|| "0".equals(string.substring(1))) {
|
||||||
d = Double.valueOf(string);
|
d = Double.valueOf(string);
|
||||||
if (!d.isInfinite() && !d.isNaN()) {
|
if (!d.isInfinite() && !d.isNaN()) {
|
||||||
return d;
|
return d;
|
||||||
|
@ -1508,11 +1510,10 @@ public class JSONObject {
|
||||||
} else {
|
} else {
|
||||||
Long myLong = new Long(string);
|
Long myLong = new Long(string);
|
||||||
if (string.equals(myLong.toString())) {
|
if (string.equals(myLong.toString())) {
|
||||||
if (myLong == myLong.intValue()) {
|
if (myLong.longValue() == myLong.intValue()) {
|
||||||
return myLong.intValue();
|
return Integer.valueOf(myLong.intValue());
|
||||||
} else {
|
|
||||||
return myLong;
|
|
||||||
}
|
}
|
||||||
|
return myLong;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception ignore) {
|
} catch (Exception ignore) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue