mirror of
https://github.com/fankes/JSON-java-compat.git
synced 2025-09-07 19:14:15 +08:00
change length comparison to isEmpty method
This commit is contained in:
@@ -810,11 +810,10 @@ public class JSONObject {
|
||||
* @return An array of field names, or null if there are no names.
|
||||
*/
|
||||
public static String[] getNames(JSONObject jo) {
|
||||
int length = jo.length();
|
||||
if (length == 0) {
|
||||
if (jo.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return jo.keySet().toArray(new String[length]);
|
||||
return jo.keySet().toArray(new String[jo.length()]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -972,15 +971,6 @@ public class JSONObject {
|
||||
return map.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if JSONObject is not empty.
|
||||
*
|
||||
* @return true if JSONObject is not empty, otherwise false.
|
||||
*/
|
||||
public boolean isNotEmpty() {
|
||||
return !map.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Produce a JSONArray containing the names of the elements of this
|
||||
* JSONObject.
|
||||
@@ -1966,7 +1956,7 @@ public class JSONObject {
|
||||
}
|
||||
|
||||
public static Writer quote(String string, Writer w) throws IOException {
|
||||
if (string == null || string.length() == 0) {
|
||||
if (string == null || string.isEmpty()) {
|
||||
w.write("\"\"");
|
||||
return w;
|
||||
}
|
||||
@@ -2245,7 +2235,7 @@ public class JSONObject {
|
||||
* If any of the values are non-finite numbers.
|
||||
*/
|
||||
public JSONArray toJSONArray(JSONArray names) throws JSONException {
|
||||
if (names == null || names.length() == 0) {
|
||||
if (names == null || names.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
JSONArray ja = new JSONArray();
|
||||
|
Reference in New Issue
Block a user