Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 26 additions & 14 deletions JSONObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ of this software and associated documentation files (the "Software"), to deal
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
Expand Down Expand Up @@ -114,15 +116,15 @@ protected final Object clone() {

/**
* A Null object is equal to the null value and to itself.
*
*
* @param object
* An object to test for nullness.
* @return true if the object parameter is the JSONObject.NULL object or
* null.
*/
@Override
public boolean equals(Object object) {
return object == null || object == this;
return object == null || object == this;
}

/**
Expand Down Expand Up @@ -1357,19 +1359,29 @@ public static Object stringToValue(String string) {
try {
if (string.indexOf('.') > -1 || string.indexOf('e') > -1
|| string.indexOf('E') > -1) {
d = Double.valueOf(string);
if (!d.isInfinite() && !d.isNaN()) {
return d;
}
BigDecimal bd = new BigDecimal( string );
d = Double.valueOf( bd.doubleValue() );
if( new BigDecimal( d.toString() ).equals( bd ) ) {
if (!d.isInfinite() && !d.isNaN()) {
return d;
}
} else {
return bd;
}
} else {
Long myLong = new Long(string);
if (string.equals(myLong.toString())) {
if (myLong == myLong.intValue()) {
return myLong.intValue();
} else {
return myLong;
}
}
BigInteger bi = new BigInteger( string );
Long myLong = Long.valueOf( bi.longValue() );
if( new BigInteger( myLong.toString() ).equals( bi ) ) {
if (string.equals(myLong.toString())) {
if (myLong == myLong.intValue()) {
return myLong.intValue();
} else {
return myLong;
}
}
} else {
return bi;
}
}
} catch (Exception ignore) {
}
Expand Down