@@ -28,6 +28,7 @@ of this software and associated documentation files (the "Software"), to deal
2828import java .io .StringWriter ;
2929import java .io .Writer ;
3030import java .lang .reflect .Array ;
31+ import java .math .*;
3132import java .util .ArrayList ;
3233import java .util .Collection ;
3334import java .util .Iterator ;
@@ -75,7 +76,7 @@ of this software and associated documentation files (the "Software"), to deal
7576 * </ul>
7677 *
7778 * @author JSON.org
78- * @version 2015-06 -04
79+ * @version 2015-07 -04
7980 */
8081public class JSONArray implements Iterable <Object > {
8182
@@ -246,6 +247,46 @@ public double getDouble(int index) throws JSONException {
246247 }
247248 }
248249
250+ /**
251+ * Get the BigDecimal value associated with an index.
252+ *
253+ * @param index
254+ * The index must be between 0 and length() - 1.
255+ * @return The value.
256+ * @throws JSONException
257+ * If the key is not found or if the value cannot be converted
258+ * to a BigDecimal.
259+ */
260+ public BigDecimal getBigDecimal (int index ) throws JSONException {
261+ Object object = this .get (index );
262+ try {
263+ return new BigDecimal (object .toString ());
264+ } catch (Exception e ) {
265+ throw new JSONException ("JSONArray[" + index +
266+ "] could not convert to BigDecimal." );
267+ }
268+ }
269+
270+ /**
271+ * Get the BigInteger value associated with an index.
272+ *
273+ * @param index
274+ * The index must be between 0 and length() - 1.
275+ * @return The value.
276+ * @throws JSONException
277+ * If the key is not found or if the value cannot be converted
278+ * to a BigInteger.
279+ */
280+ public BigInteger getBigInteger (int index ) throws JSONException {
281+ Object object = this .get (index );
282+ try {
283+ return new BigInteger (object .toString ());
284+ } catch (Exception e ) {
285+ throw new JSONException ("JSONArray[" + index +
286+ "] could not convert to BigInteger." );
287+ }
288+ }
289+
249290 /**
250291 * Get the int value associated with an index.
251292 *
0 commit comments