Skip to content

Commit fcdb867

Browse files
author
John J. Aylward
committed
grr, forgot to save changes on last commit
1 parent c46774c commit fcdb867

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

JSONArray.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ public double optDouble(int index, double defaultValue) {
536536
}
537537

538538
/**
539-
* Get the optional double value associated with an index. NaN is returned
539+
* Get the optional float value associated with an index. NaN is returned
540540
* if there is no value for the index, or if the value is not a number and
541541
* cannot be converted to a number.
542542
*
@@ -549,7 +549,7 @@ public float optFloat(int index) {
549549
}
550550

551551
/**
552-
* Get the optional double value associated with an index. The defaultValue
552+
* Get the optional float value associated with an index. The defaultValue
553553
* is returned if there is no value for the index, or if the value is not a
554554
* number and cannot be converted to a number.
555555
*
@@ -808,6 +808,22 @@ public long optLong(int index, long defaultValue) {
808808
return defaultValue;
809809
}
810810

811+
/**
812+
* Get an optional {@link Number} value associated with a key, or <code>null</code>
813+
* if there is no such key or if the value is not a number. If the value is a string,
814+
* an attempt will be made to evaluate it as a number ({@link BigDecimal}). This method
815+
* would be used in cases where type coercion of the number value is unwanted.
816+
*
817+
* @param index
818+
* The index must be between 0 and length() - 1.
819+
* @param defaultValue
820+
* The default.
821+
* @return An object which is the value.
822+
*/
823+
public Number optNumber(int index) {
824+
return this.optNumber(index, null);
825+
}
826+
811827
/**
812828
* Get an optional {@link Number} value associated with a key, or the default if there
813829
* is no such key or if the value is not a number. If the value is a string,

JSONObject.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,8 +1075,8 @@ public double optDouble(String key, double defaultValue) {
10751075
* if there is no value for the index, or if the value is not a number and
10761076
* cannot be converted to a number.
10771077
*
1078-
* @param index
1079-
* The index must be between 0 and length() - 1.
1078+
* @param key
1079+
* A key string.
10801080
* @return The value.
10811081
*/
10821082
public float optFloat(String key) {
@@ -1088,8 +1088,8 @@ public float optFloat(String key) {
10881088
* is returned if there is no value for the index, or if the value is not a
10891089
* number and cannot be converted to a number.
10901090
*
1091-
* @param index
1092-
* subscript
1091+
* @param key
1092+
* A key string.
10931093
* @param defaultValue
10941094
* The default value.
10951095
* @return The value.

0 commit comments

Comments
 (0)