|
1 | 1 | package org.json;
|
2 | 2 |
|
3 | 3 | /*
|
4 |
| -Copyright (c) 2002 JSON.org |
| 4 | +Copyright (c) 2015 JSON.org |
5 | 5 |
|
6 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy
|
7 | 7 | of this software and associated documentation files (the "Software"), to deal
|
@@ -30,7 +30,7 @@ of this software and associated documentation files (the "Software"), to deal
|
30 | 30 | * This provides static methods to convert an XML text into a JSONObject,
|
31 | 31 | * and to covert a JSONObject into an XML text.
|
32 | 32 | * @author JSON.org
|
33 |
| - * @version 2014-05-03 |
| 33 | + * @version 2015-10-14 |
34 | 34 | */
|
35 | 35 | public class XML {
|
36 | 36 |
|
@@ -468,23 +468,25 @@ public static String toString(Object object, String tagName)
|
468 | 468 | // XML does not have good support for arrays. If an array appears in a place
|
469 | 469 | // where XML is lacking, synthesize an <array> element.
|
470 | 470 |
|
471 |
| - } else { |
| 471 | + } |
| 472 | + if(object!=null){ |
472 | 473 | if (object.getClass().isArray()) {
|
473 | 474 | object = new JSONArray(object);
|
474 | 475 | }
|
| 476 | + |
475 | 477 | if (object instanceof JSONArray) {
|
476 | 478 | ja = (JSONArray)object;
|
477 | 479 | length = ja.length();
|
478 | 480 | for (i = 0; i < length; i += 1) {
|
479 | 481 | sb.append(toString(ja.opt(i), tagName == null ? "array" : tagName));
|
480 | 482 | }
|
481 | 483 | return sb.toString();
|
482 |
| - } else { |
483 |
| - string = (object == null) ? "null" : escape(object.toString()); |
484 |
| - return (tagName == null) ? "\"" + string + "\"" : |
485 |
| - (string.length() == 0) ? "<" + tagName + "/>" : |
486 |
| - "<" + tagName + ">" + string + "</" + tagName + ">"; |
487 | 484 | }
|
488 | 485 | }
|
| 486 | + string = (object == null) ? "null" : escape(object.toString()); |
| 487 | + return (tagName == null) ? "\"" + string + "\"" : |
| 488 | + (string.length() == 0) ? "<" + tagName + "/>" : |
| 489 | + "<" + tagName + ">" + string + "</" + tagName + ">"; |
| 490 | + |
489 | 491 | }
|
490 | 492 | }
|
0 commit comments