1
0
Fork 0
mirror of https://github.com/ethauvin/JSON-java.git synced 2025-06-17 07:50:52 -07:00

optString

This commit is contained in:
unknown 2011-12-19 17:31:55 -08:00
parent 806900e0d1
commit 6394d92279

66
JSONArray.java Executable file → Normal file
View file

@ -76,7 +76,7 @@ import java.util.Map;
* </ul> * </ul>
* @author JSON.org * @author JSON.org
* @version 2011-11-24 * @version 2011-12-19
*/ */
public class JSONArray { public class JSONArray {
@ -105,29 +105,29 @@ public class JSONArray {
throw x.syntaxError("A JSONArray text must start with '['"); throw x.syntaxError("A JSONArray text must start with '['");
} }
if (x.nextClean() != ']') { if (x.nextClean() != ']') {
x.back(); x.back();
for (;;) { for (;;) {
if (x.nextClean() == ',') { if (x.nextClean() == ',') {
x.back(); x.back();
this.myArrayList.add(JSONObject.NULL); this.myArrayList.add(JSONObject.NULL);
} else { } else {
x.back(); x.back();
this.myArrayList.add(x.nextValue()); this.myArrayList.add(x.nextValue());
} }
switch (x.nextClean()) { switch (x.nextClean()) {
case ';': case ';':
case ',': case ',':
if (x.nextClean() == ']') { if (x.nextClean() == ']') {
return; return;
} }
x.back(); x.back();
break; break;
case ']': case ']':
return; return;
default: default:
throw x.syntaxError("Expected a ',' or ']'"); throw x.syntaxError("Expected a ',' or ']'");
} }
} }
} }
} }
@ -149,13 +149,13 @@ public class JSONArray {
* @param collection A Collection. * @param collection A Collection.
*/ */
public JSONArray(Collection collection) { public JSONArray(Collection collection) {
this.myArrayList = new ArrayList(); this.myArrayList = new ArrayList();
if (collection != null) { if (collection != null) {
Iterator iter = collection.iterator(); Iterator iter = collection.iterator();
while (iter.hasNext()) { while (iter.hasNext()) {
this.myArrayList.add(JSONObject.wrap(iter.next())); this.myArrayList.add(JSONObject.wrap(iter.next()));
} }
} }
} }
@ -555,8 +555,8 @@ public class JSONArray {
public String optString(int index, String defaultValue) { public String optString(int index, String defaultValue) {
Object object = this.opt(index); Object object = this.opt(index);
return JSONObject.NULL.equals(object) return JSONObject.NULL.equals(object)
? object.toString() ? defaultValue
: defaultValue; : object.toString();
} }
@ -775,7 +775,7 @@ public class JSONArray {
* or null if there was no value. * or null if there was no value.
*/ */
public Object remove(int index) { public Object remove(int index) {
Object o = this.opt(index); Object o = this.opt(index);
this.myArrayList.remove(index); this.myArrayList.remove(index);
return o; return o;
} }