mirror of
https://github.com/ethauvin/JSON-java.git
synced 2025-06-17 07:50:52 -07:00
.getString(...) now throws if there is no property or if it is not a string
This commit is contained in:
parent
dced076cd4
commit
f4cb14728f
3 changed files with 32 additions and 17 deletions
|
@ -78,7 +78,7 @@ import java.util.Map;
|
|||
* </ul>
|
||||
|
||||
* @author JSON.org
|
||||
* @version 2010-12-28
|
||||
* @version 2011-05-04
|
||||
*/
|
||||
public class JSONArray {
|
||||
|
||||
|
@ -319,11 +319,14 @@ public class JSONArray {
|
|||
* Get the string associated with an index.
|
||||
* @param index The index must be between 0 and length() - 1.
|
||||
* @return A string value.
|
||||
* @throws JSONException If there is no value for the index.
|
||||
* @throws JSONException If there is no string value for the index.
|
||||
*/
|
||||
public String getString(int index) throws JSONException {
|
||||
Object object = get(index);
|
||||
return object == JSONObject.NULL ? null : object.toString();
|
||||
if (object instanceof String) {
|
||||
return (String)object;
|
||||
}
|
||||
throw new JSONException("JSONArray[" + index + "] not a string.");
|
||||
}
|
||||
|
||||
|
||||
|
@ -722,7 +725,7 @@ public class JSONArray {
|
|||
|
||||
/**
|
||||
* Put a value in the JSONArray, where the value will be a
|
||||
* JSONObject which is produced from a Map.
|
||||
* JSONObject that is produced from a Map.
|
||||
* @param index The subscript.
|
||||
* @param value The Map value.
|
||||
* @return this.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue