mirror of
https://github.com/fankes/JSON-java-compat.git
synced 2025-09-06 18:55:30 +08:00
Fixes possible NPE
This commit is contained in:
14
XML.java
14
XML.java
@@ -468,10 +468,12 @@ public class XML {
|
|||||||
// XML does not have good support for arrays. If an array appears in a place
|
// XML does not have good support for arrays. If an array appears in a place
|
||||||
// where XML is lacking, synthesize an <array> element.
|
// where XML is lacking, synthesize an <array> element.
|
||||||
|
|
||||||
} else {
|
}
|
||||||
|
if(object!=null){
|
||||||
if (object.getClass().isArray()) {
|
if (object.getClass().isArray()) {
|
||||||
object = new JSONArray(object);
|
object = new JSONArray(object);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (object instanceof JSONArray) {
|
if (object instanceof JSONArray) {
|
||||||
ja = (JSONArray)object;
|
ja = (JSONArray)object;
|
||||||
length = ja.length();
|
length = ja.length();
|
||||||
@@ -479,12 +481,12 @@ public class XML {
|
|||||||
sb.append(toString(ja.opt(i), tagName == null ? "array" : tagName));
|
sb.append(toString(ja.opt(i), tagName == null ? "array" : tagName));
|
||||||
}
|
}
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
} else {
|
|
||||||
string = (object == null) ? "null" : escape(object.toString());
|
|
||||||
return (tagName == null) ? "\"" + string + "\"" :
|
|
||||||
(string.length() == 0) ? "<" + tagName + "/>" :
|
|
||||||
"<" + tagName + ">" + string + "</" + tagName + ">";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
string = (object == null) ? "null" : escape(object.toString());
|
||||||
|
return (tagName == null) ? "\"" + string + "\"" :
|
||||||
|
(string.length() == 0) ? "<" + tagName + "/>" :
|
||||||
|
"<" + tagName + ">" + string + "</" + tagName + ">";
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user