mirror of
https://github.com/ethauvin/JSON-java.git
synced 2025-06-17 07:50:52 -07:00
optString
This commit is contained in:
parent
806900e0d1
commit
6394d92279
1 changed files with 33 additions and 33 deletions
66
JSONArray.java
Executable file → Normal file
66
JSONArray.java
Executable file → Normal 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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue