mirror of
https://github.com/ethauvin/JSON-java.git
synced 2025-06-17 07:50:52 -07:00
Fixes possible NPE
This commit is contained in:
parent
b0191a6acf
commit
ceba8e8c3d
1 changed files with 8 additions and 6 deletions
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 + ">";
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue