Skip to content

Commit 6ab6f06

Browse files
committed
latest
1 parent 03c4fc7 commit 6ab6f06

2 files changed

Lines changed: 43 additions & 2 deletions

File tree

JSONArray.java

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ of this software and associated documentation files (the "Software"), to deal
2828
import java.io.StringWriter;
2929
import java.io.Writer;
3030
import java.lang.reflect.Array;
31+
import java.math.*;
3132
import java.util.ArrayList;
3233
import java.util.Collection;
3334
import 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
*/
8081
public 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
*

JSONObject.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ of this software and associated documentation files (the "Software"), to deal
9292
* </ul>
9393
*
9494
* @author JSON.org
95-
* @version 2015-06-20
95+
* @version 2015-07-04
9696
*/
9797
public class JSONObject {
9898
/**

0 commit comments

Comments
 (0)