diff --git a/JSONArray.java b/JSONArray.java index deede03..22d4ab7 100644 --- a/JSONArray.java +++ b/JSONArray.java @@ -28,6 +28,7 @@ import java.io.IOException; import java.io.StringWriter; import java.io.Writer; import java.lang.reflect.Array; +import java.math.*; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; @@ -75,7 +76,7 @@ import java.util.Map; * * * @author JSON.org - * @version 2015-06-04 + * @version 2015-07-04 */ public class JSONArray implements Iterable { @@ -246,6 +247,46 @@ public class JSONArray implements Iterable { } } + /** + * Get the BigDecimal value associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The value. + * @throws JSONException + * If the key is not found or if the value cannot be converted + * to a BigDecimal. + */ + public BigDecimal getBigDecimal (int index) throws JSONException { + Object object = this.get(index); + try { + return new BigDecimal(object.toString()); + } catch (Exception e) { + throw new JSONException("JSONArray[" + index + + "] could not convert to BigDecimal."); + } + } + + /** + * Get the BigInteger value associated with an index. + * + * @param index + * The index must be between 0 and length() - 1. + * @return The value. + * @throws JSONException + * If the key is not found or if the value cannot be converted + * to a BigInteger. + */ + public BigInteger getBigInteger (int index) throws JSONException { + Object object = this.get(index); + try { + return new BigInteger(object.toString()); + } catch (Exception e) { + throw new JSONException("JSONArray[" + index + + "] could not convert to BigInteger."); + } + } + /** * Get the int value associated with an index. * diff --git a/JSONObject.java b/JSONObject.java index 14f58b8..24223c5 100755 --- a/JSONObject.java +++ b/JSONObject.java @@ -92,7 +92,7 @@ import java.util.Set; * * * @author JSON.org - * @version 2015-06-20 + * @version 2015-07-04 */ public class JSONObject { /**