1 |
|
package org.json; |
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
import java.io.Reader; |
28 |
|
import java.io.StringReader; |
29 |
|
import java.util.Iterator; |
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
|
35 |
|
@author |
36 |
|
@version |
37 |
|
|
38 |
|
@SuppressWarnings("boxing") |
|
|
| 0% |
Uncovered Elements: 397 (397) |
Complexity: 105 |
Complexity Density: 0.45 |
|
39 |
|
public class XML |
40 |
|
{ |
41 |
|
|
42 |
|
public static final Character AMP = '&'; |
43 |
|
|
44 |
|
|
45 |
|
public static final Character APOS = '\''; |
46 |
|
|
47 |
|
|
48 |
|
public static final Character BANG = '!'; |
49 |
|
|
50 |
|
|
51 |
|
public static final Character EQ = '='; |
52 |
|
|
53 |
|
|
54 |
|
public static final Character GT = '>'; |
55 |
|
|
56 |
|
|
57 |
|
public static final Character LT = '<'; |
58 |
|
|
59 |
|
|
60 |
|
public static final Character QUEST = '?'; |
61 |
|
|
62 |
|
|
63 |
|
public static final Character QUOT = '"'; |
64 |
|
|
65 |
|
|
66 |
|
public static final Character SLASH = '/'; |
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
@see |
75 |
|
|
76 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
77 |
0 |
private static Iterable<Integer> codePointIterator(final String string)... |
78 |
|
{ |
79 |
0 |
return new Iterable<Integer>() |
80 |
|
{ |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
81 |
0 |
@Override... |
82 |
|
public Iterator<Integer> iterator() |
83 |
|
{ |
84 |
0 |
return new Iterator<Integer>() |
85 |
|
{ |
86 |
|
private int nextIndex = 0; |
87 |
|
|
88 |
|
private int length = string.length(); |
89 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
90 |
0 |
@Override... |
91 |
|
public boolean hasNext() |
92 |
|
{ |
93 |
0 |
return this.nextIndex < this.length; |
94 |
|
} |
95 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
96 |
0 |
@Override... |
97 |
|
public Integer next() |
98 |
|
{ |
99 |
0 |
int result = string.codePointAt(this.nextIndex); |
100 |
0 |
this.nextIndex += Character.charCount(result); |
101 |
0 |
return result; |
102 |
|
} |
103 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
104 |
0 |
@Override... |
105 |
|
public void remove() |
106 |
|
{ |
107 |
0 |
throw new UnsupportedOperationException(); |
108 |
|
} |
109 |
|
}; |
110 |
|
} |
111 |
|
}; |
112 |
|
} |
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
@param |
126 |
|
|
127 |
|
@return |
128 |
|
|
|
|
| 0% |
Uncovered Elements: 27 (27) |
Complexity: 7 |
Complexity Density: 0.28 |
|
129 |
0 |
public static String escape(String string)... |
130 |
|
{ |
131 |
0 |
StringBuilder sb = new StringBuilder(string.length()); |
132 |
0 |
for (final int cp : codePointIterator(string)) |
133 |
|
{ |
134 |
0 |
switch (cp) |
135 |
|
{ |
136 |
0 |
case '&': |
137 |
0 |
sb.append("&"); |
138 |
0 |
break; |
139 |
0 |
case '<': |
140 |
0 |
sb.append("<"); |
141 |
0 |
break; |
142 |
0 |
case '>': |
143 |
0 |
sb.append(">"); |
144 |
0 |
break; |
145 |
0 |
case '"': |
146 |
0 |
sb.append("""); |
147 |
0 |
break; |
148 |
0 |
case '\'': |
149 |
0 |
sb.append("'"); |
150 |
0 |
break; |
151 |
0 |
default: |
152 |
0 |
if (mustEscape(cp)) |
153 |
|
{ |
154 |
0 |
sb.append("&#x"); |
155 |
0 |
sb.append(Integer.toHexString(cp)); |
156 |
0 |
sb.append(';'); |
157 |
|
} |
158 |
|
else |
159 |
|
{ |
160 |
0 |
sb.appendCodePoint(cp); |
161 |
|
} |
162 |
|
} |
163 |
|
} |
164 |
0 |
return sb.toString(); |
165 |
|
} |
166 |
|
|
167 |
|
|
168 |
|
@param |
169 |
|
|
170 |
|
@return |
171 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
172 |
0 |
private static boolean mustEscape(int cp)... |
173 |
|
{ |
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
|
178 |
|
|
179 |
|
|
180 |
|
|
181 |
|
|
182 |
|
|
183 |
0 |
return (Character.isISOControl(cp) && cp != 0x9 && cp != 0xA |
184 |
|
&& cp != 0xD) || !( |
185 |
|
|
186 |
|
(cp >= 0x20 && cp <= 0xD7FF) || (cp >= 0xE000 && cp <= 0xFFFD) |
187 |
|
|| (cp >= 0x10000 && cp <= 0x10FFFF)); |
188 |
|
} |
189 |
|
|
190 |
|
|
191 |
|
|
192 |
|
|
193 |
|
@param |
194 |
|
|
195 |
|
@return |
196 |
|
|
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 4 |
Complexity Density: 0.33 |
|
197 |
0 |
public static String unescape(String string)... |
198 |
|
{ |
199 |
0 |
StringBuilder sb = new StringBuilder(string.length()); |
200 |
0 |
for (int i = 0, length = string.length(); i < length; i++) |
201 |
|
{ |
202 |
0 |
char c = string.charAt(i); |
203 |
0 |
if (c == '&') |
204 |
|
{ |
205 |
0 |
final int semic = string.indexOf(';', i); |
206 |
0 |
if (semic > i) |
207 |
|
{ |
208 |
0 |
final String entity = string.substring(i + 1, semic); |
209 |
0 |
sb.append(XMLTokener.unescapeEntity(entity)); |
210 |
|
|
211 |
0 |
i += entity.length() + 1; |
212 |
|
} |
213 |
|
else |
214 |
|
{ |
215 |
|
|
216 |
|
|
217 |
0 |
sb.append(c); |
218 |
|
} |
219 |
|
} |
220 |
|
else |
221 |
|
{ |
222 |
|
|
223 |
0 |
sb.append(c); |
224 |
|
} |
225 |
|
} |
226 |
0 |
return sb.toString(); |
227 |
|
} |
228 |
|
|
229 |
|
|
230 |
|
|
231 |
|
|
232 |
|
|
233 |
|
@param |
234 |
|
|
235 |
|
@throws |
236 |
|
|
237 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 4 |
Complexity Density: 0.67 |
|
238 |
0 |
public static void noSpace(String string) throws JSONException... |
239 |
|
{ |
240 |
0 |
int i, length = string.length(); |
241 |
0 |
if (length == 0) |
242 |
|
{ |
243 |
0 |
throw new JSONException("Empty string."); |
244 |
|
} |
245 |
0 |
for (i = 0; i < length; i += 1) |
246 |
|
{ |
247 |
0 |
if (Character.isWhitespace(string.charAt(i))) |
248 |
|
{ |
249 |
0 |
throw new JSONException( |
250 |
|
"'" + string + "' contains a space character."); |
251 |
|
} |
252 |
|
} |
253 |
|
} |
254 |
|
|
255 |
|
|
256 |
|
|
257 |
|
|
258 |
|
@param |
259 |
|
|
260 |
|
@param |
261 |
|
|
262 |
|
@param |
263 |
|
|
264 |
|
@return |
265 |
|
@throws |
266 |
|
|
|
|
| 0% |
Uncovered Elements: 160 (160) |
Complexity: 37 |
Complexity Density: 0.41 |
|
267 |
0 |
private static boolean parse(XMLTokener x, JSONObject context,... |
268 |
|
String name, boolean keepStrings) throws JSONException |
269 |
|
{ |
270 |
0 |
char c; |
271 |
0 |
int i; |
272 |
0 |
JSONObject jsonobject = null; |
273 |
0 |
String string; |
274 |
0 |
String tagName; |
275 |
0 |
Object token; |
276 |
|
|
277 |
|
|
278 |
|
|
279 |
|
|
280 |
|
|
281 |
|
|
282 |
|
|
283 |
|
|
284 |
|
|
285 |
|
|
286 |
|
|
287 |
0 |
token = x.nextToken(); |
288 |
|
|
289 |
|
|
290 |
|
|
291 |
0 |
if (token == BANG) |
292 |
|
{ |
293 |
0 |
c = x.next(); |
294 |
0 |
if (c == '-') |
295 |
|
{ |
296 |
0 |
if (x.next() == '-') |
297 |
|
{ |
298 |
0 |
x.skipPast("-->"); |
299 |
0 |
return false; |
300 |
|
} |
301 |
0 |
x.back(); |
302 |
|
} |
303 |
0 |
else if (c == '[') |
304 |
|
{ |
305 |
0 |
token = x.nextToken(); |
306 |
0 |
if ("CDATA".equals(token)) |
307 |
|
{ |
308 |
0 |
if (x.next() == '[') |
309 |
|
{ |
310 |
0 |
string = x.nextCDATA(); |
311 |
0 |
if (string.length() > 0) |
312 |
|
{ |
313 |
0 |
context.accumulate("content", string); |
314 |
|
} |
315 |
0 |
return false; |
316 |
|
} |
317 |
|
} |
318 |
0 |
throw x.syntaxError("Expected 'CDATA['"); |
319 |
|
} |
320 |
0 |
i = 1; |
321 |
0 |
do |
322 |
|
{ |
323 |
0 |
token = x.nextMeta(); |
324 |
0 |
if (token == null) |
325 |
|
{ |
326 |
0 |
throw x.syntaxError("Missing '>' after '<!'."); |
327 |
|
} |
328 |
0 |
else if (token == LT) |
329 |
|
{ |
330 |
0 |
i += 1; |
331 |
|
} |
332 |
0 |
else if (token == GT) |
333 |
|
{ |
334 |
0 |
i -= 1; |
335 |
|
} |
336 |
0 |
} while (i > 0); |
337 |
0 |
return false; |
338 |
|
} |
339 |
0 |
else if (token == QUEST) |
340 |
|
{ |
341 |
|
|
342 |
|
|
343 |
0 |
x.skipPast("?>"); |
344 |
0 |
return false; |
345 |
|
} |
346 |
0 |
else if (token == SLASH) |
347 |
|
{ |
348 |
|
|
349 |
|
|
350 |
|
|
351 |
0 |
token = x.nextToken(); |
352 |
0 |
if (name == null) |
353 |
|
{ |
354 |
0 |
throw x.syntaxError("Mismatched close tag " + token); |
355 |
|
} |
356 |
0 |
if (!token.equals(name)) |
357 |
|
{ |
358 |
0 |
throw x.syntaxError("Mismatched " + name + " and " + token); |
359 |
|
} |
360 |
0 |
if (x.nextToken() != GT) |
361 |
|
{ |
362 |
0 |
throw x.syntaxError("Misshaped close tag"); |
363 |
|
} |
364 |
0 |
return true; |
365 |
|
|
366 |
|
} |
367 |
0 |
else if (token instanceof Character) |
368 |
|
{ |
369 |
0 |
throw x.syntaxError("Misshaped tag"); |
370 |
|
|
371 |
|
|
372 |
|
|
373 |
|
} |
374 |
|
else |
375 |
|
{ |
376 |
0 |
tagName = (String) token; |
377 |
0 |
token = null; |
378 |
0 |
jsonobject = new JSONObject(); |
379 |
0 |
for (;;) |
380 |
|
{ |
381 |
0 |
if (token == null) |
382 |
|
{ |
383 |
0 |
token = x.nextToken(); |
384 |
|
} |
385 |
|
|
386 |
0 |
if (token instanceof String) |
387 |
|
{ |
388 |
0 |
string = (String) token; |
389 |
0 |
token = x.nextToken(); |
390 |
0 |
if (token == EQ) |
391 |
|
{ |
392 |
0 |
token = x.nextToken(); |
393 |
0 |
if (!(token instanceof String)) |
394 |
|
{ |
395 |
0 |
throw x.syntaxError("Missing value"); |
396 |
|
} |
397 |
0 |
jsonobject.accumulate(string, keepStrings ? ((String) token) |
398 |
|
: stringToValue((String) token)); |
399 |
0 |
token = null; |
400 |
|
} |
401 |
|
else |
402 |
|
{ |
403 |
0 |
jsonobject.accumulate(string, ""); |
404 |
|
} |
405 |
|
|
406 |
|
} |
407 |
0 |
else if (token == SLASH) |
408 |
|
{ |
409 |
|
|
410 |
0 |
if (x.nextToken() != GT) |
411 |
|
{ |
412 |
0 |
throw x.syntaxError("Misshaped tag"); |
413 |
|
} |
414 |
0 |
if (jsonobject.length() > 0) |
415 |
|
{ |
416 |
0 |
context.accumulate(tagName, jsonobject); |
417 |
|
} |
418 |
|
else |
419 |
|
{ |
420 |
0 |
context.accumulate(tagName, ""); |
421 |
|
} |
422 |
0 |
return false; |
423 |
|
|
424 |
|
} |
425 |
0 |
else if (token == GT) |
426 |
|
{ |
427 |
|
|
428 |
0 |
for (;;) |
429 |
|
{ |
430 |
0 |
token = x.nextContent(); |
431 |
0 |
if (token == null) |
432 |
|
{ |
433 |
0 |
if (tagName != null) |
434 |
|
{ |
435 |
0 |
throw x.syntaxError("Unclosed tag " + tagName); |
436 |
|
} |
437 |
0 |
return false; |
438 |
|
} |
439 |
0 |
else if (token instanceof String) |
440 |
|
{ |
441 |
0 |
string = (String) token; |
442 |
0 |
if (string.length() > 0) |
443 |
|
{ |
444 |
0 |
jsonobject.accumulate("content", |
445 |
0 |
keepStrings ? string : stringToValue(string)); |
446 |
|
} |
447 |
|
|
448 |
|
} |
449 |
0 |
else if (token == LT) |
450 |
|
{ |
451 |
|
|
452 |
0 |
if (parse(x, jsonobject, tagName, keepStrings)) |
453 |
|
{ |
454 |
0 |
if (jsonobject.length() == 0) |
455 |
|
{ |
456 |
0 |
context.accumulate(tagName, ""); |
457 |
|
} |
458 |
0 |
else if (jsonobject.length() == 1 |
459 |
|
&& jsonobject.opt("content") != null) |
460 |
|
{ |
461 |
0 |
context.accumulate(tagName, jsonobject.opt("content")); |
462 |
|
} |
463 |
|
else |
464 |
|
{ |
465 |
0 |
context.accumulate(tagName, jsonobject); |
466 |
|
} |
467 |
0 |
return false; |
468 |
|
} |
469 |
|
} |
470 |
|
} |
471 |
|
} |
472 |
|
else |
473 |
|
{ |
474 |
0 |
throw x.syntaxError("Misshaped tag"); |
475 |
|
} |
476 |
|
} |
477 |
|
} |
478 |
|
} |
479 |
|
|
480 |
|
|
481 |
|
@link |
482 |
|
|
483 |
|
@param |
484 |
|
|
485 |
|
@return |
486 |
|
|
487 |
|
|
488 |
|
|
489 |
|
|
|
|
| 0% |
Uncovered Elements: 39 (39) |
Complexity: 17 |
Complexity Density: 0.81 |
|
490 |
0 |
public static Object stringToValue(String string)... |
491 |
|
{ |
492 |
0 |
if (string.equals("")) |
493 |
|
{ |
494 |
0 |
return string; |
495 |
|
} |
496 |
0 |
if (string.equalsIgnoreCase("true")) |
497 |
|
{ |
498 |
0 |
return Boolean.TRUE; |
499 |
|
} |
500 |
0 |
if (string.equalsIgnoreCase("false")) |
501 |
|
{ |
502 |
0 |
return Boolean.FALSE; |
503 |
|
} |
504 |
0 |
if (string.equalsIgnoreCase("null")) |
505 |
|
{ |
506 |
0 |
return JSONObject.NULL; |
507 |
|
} |
508 |
|
|
509 |
|
|
510 |
|
|
511 |
|
|
512 |
|
|
513 |
|
|
514 |
0 |
char initial = string.charAt(0); |
515 |
0 |
if ((initial >= '0' && initial <= '9') || initial == '-') |
516 |
|
{ |
517 |
0 |
try |
518 |
|
{ |
519 |
|
|
520 |
|
|
521 |
0 |
if (string.indexOf('.') > -1 || string.indexOf('e') > -1 |
522 |
|
|| string.indexOf('E') > -1 || "-0".equals(string)) |
523 |
|
{ |
524 |
0 |
Double d = Double.valueOf(string); |
525 |
0 |
if (!d.isInfinite() && !d.isNaN()) |
526 |
|
{ |
527 |
0 |
return d; |
528 |
|
} |
529 |
|
} |
530 |
|
else |
531 |
|
{ |
532 |
0 |
Long myLong = Long.valueOf(string); |
533 |
0 |
if (string.equals(myLong.toString())) |
534 |
|
{ |
535 |
0 |
if (myLong.longValue() == myLong.intValue()) |
536 |
|
{ |
537 |
0 |
return Integer.valueOf(myLong.intValue()); |
538 |
|
} |
539 |
0 |
return myLong; |
540 |
|
} |
541 |
|
} |
542 |
|
} catch (Exception ignore) |
543 |
|
{ |
544 |
|
} |
545 |
|
} |
546 |
0 |
return string; |
547 |
|
} |
548 |
|
|
549 |
|
|
550 |
|
|
551 |
|
|
552 |
|
|
553 |
|
|
554 |
|
|
555 |
|
|
556 |
|
|
557 |
|
|
558 |
|
|
559 |
|
@param |
560 |
|
|
561 |
|
@return |
562 |
|
@throws |
563 |
|
|
564 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
565 |
0 |
public static JSONObject toJSONObject(String string) throws JSONException... |
566 |
|
{ |
567 |
0 |
return toJSONObject(string, false); |
568 |
|
} |
569 |
|
|
570 |
|
|
571 |
|
|
572 |
|
|
573 |
|
|
574 |
|
|
575 |
|
|
576 |
|
|
577 |
|
|
578 |
|
|
579 |
|
|
580 |
|
@param |
581 |
|
|
582 |
|
@return |
583 |
|
@throws |
584 |
|
|
585 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
586 |
0 |
public static JSONObject toJSONObject(Reader reader) throws JSONException... |
587 |
|
{ |
588 |
0 |
return toJSONObject(reader, false); |
589 |
|
} |
590 |
|
|
591 |
|
|
592 |
|
|
593 |
|
|
594 |
|
|
595 |
|
|
596 |
|
|
597 |
|
|
598 |
|
|
599 |
|
|
600 |
|
|
601 |
|
|
602 |
|
|
603 |
|
|
604 |
|
@param |
605 |
|
|
606 |
|
@param |
607 |
|
|
608 |
|
|
609 |
|
@return |
610 |
|
@throws |
611 |
|
|
612 |
|
|
|
|
| 0% |
Uncovered Elements: 11 (11) |
Complexity: 3 |
Complexity Density: 0.43 |
|
613 |
0 |
public static JSONObject toJSONObject(Reader reader, boolean keepStrings)... |
614 |
|
throws JSONException |
615 |
|
{ |
616 |
0 |
JSONObject jo = new JSONObject(); |
617 |
0 |
XMLTokener x = new XMLTokener(reader); |
618 |
0 |
while (x.more()) |
619 |
|
{ |
620 |
0 |
x.skipPast("<"); |
621 |
0 |
if (x.more()) |
622 |
|
{ |
623 |
0 |
parse(x, jo, null, keepStrings); |
624 |
|
} |
625 |
|
} |
626 |
0 |
return jo; |
627 |
|
} |
628 |
|
|
629 |
|
|
630 |
|
|
631 |
|
|
632 |
|
|
633 |
|
|
634 |
|
|
635 |
|
|
636 |
|
|
637 |
|
|
638 |
|
|
639 |
|
|
640 |
|
|
641 |
|
|
642 |
|
@param |
643 |
|
|
644 |
|
@param |
645 |
|
|
646 |
|
|
647 |
|
@return |
648 |
|
@throws |
649 |
|
|
650 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
651 |
0 |
public static JSONObject toJSONObject(String string, boolean keepStrings)... |
652 |
|
throws JSONException |
653 |
|
{ |
654 |
0 |
return toJSONObject(new StringReader(string), keepStrings); |
655 |
|
} |
656 |
|
|
657 |
|
|
658 |
|
|
659 |
|
|
660 |
|
@param |
661 |
|
|
662 |
|
@return |
663 |
|
@throws |
664 |
|
|
665 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
666 |
0 |
public static String toString(Object object) throws JSONException... |
667 |
|
{ |
668 |
0 |
return toString(object, null); |
669 |
|
} |
670 |
|
|
671 |
|
|
672 |
|
|
673 |
|
|
674 |
|
@param |
675 |
|
|
676 |
|
@param |
677 |
|
|
678 |
|
@return |
679 |
|
@throws |
680 |
|
|
681 |
|
|
|
|
| 0% |
Uncovered Elements: 101 (101) |
Complexity: 23 |
Complexity Density: 0.38 |
|
682 |
0 |
public static String toString(final Object object, final String tagName)... |
683 |
|
throws JSONException |
684 |
|
{ |
685 |
0 |
StringBuilder sb = new StringBuilder(); |
686 |
0 |
JSONArray ja; |
687 |
0 |
JSONObject jo; |
688 |
0 |
String string; |
689 |
|
|
690 |
0 |
if (object instanceof JSONObject) |
691 |
|
{ |
692 |
|
|
693 |
|
|
694 |
0 |
if (tagName != null) |
695 |
|
{ |
696 |
0 |
sb.append('<'); |
697 |
0 |
sb.append(tagName); |
698 |
0 |
sb.append('>'); |
699 |
|
} |
700 |
|
|
701 |
|
|
702 |
|
|
703 |
0 |
jo = (JSONObject) object; |
704 |
0 |
for (final String key : jo.keySet()) |
705 |
|
{ |
706 |
0 |
Object value = jo.opt(key); |
707 |
0 |
if (value == null) |
708 |
|
{ |
709 |
0 |
value = ""; |
710 |
|
} |
711 |
0 |
else if (value.getClass().isArray()) |
712 |
|
{ |
713 |
0 |
value = new JSONArray(value); |
714 |
|
} |
715 |
|
|
716 |
|
|
717 |
0 |
if ("content".equals(key)) |
718 |
|
{ |
719 |
0 |
if (value instanceof JSONArray) |
720 |
|
{ |
721 |
0 |
ja = (JSONArray) value; |
722 |
0 |
int jaLength = ja.length(); |
723 |
|
|
724 |
0 |
for (int i = 0; i < jaLength; i++) |
725 |
|
{ |
726 |
0 |
if (i > 0) |
727 |
|
{ |
728 |
0 |
sb.append('\n'); |
729 |
|
} |
730 |
0 |
Object val = ja.opt(i); |
731 |
0 |
sb.append(escape(val.toString())); |
732 |
|
} |
733 |
|
} |
734 |
|
else |
735 |
|
{ |
736 |
0 |
sb.append(escape(value.toString())); |
737 |
|
} |
738 |
|
|
739 |
|
|
740 |
|
|
741 |
|
} |
742 |
0 |
else if (value instanceof JSONArray) |
743 |
|
{ |
744 |
0 |
ja = (JSONArray) value; |
745 |
0 |
int jaLength = ja.length(); |
746 |
|
|
747 |
0 |
for (int i = 0; i < jaLength; i++) |
748 |
|
{ |
749 |
0 |
Object val = ja.opt(i); |
750 |
0 |
if (val instanceof JSONArray) |
751 |
|
{ |
752 |
0 |
sb.append('<'); |
753 |
0 |
sb.append(key); |
754 |
0 |
sb.append('>'); |
755 |
0 |
sb.append(toString(val)); |
756 |
0 |
sb.append("</"); |
757 |
0 |
sb.append(key); |
758 |
0 |
sb.append('>'); |
759 |
|
} |
760 |
|
else |
761 |
|
{ |
762 |
0 |
sb.append(toString(val, key)); |
763 |
|
} |
764 |
|
} |
765 |
|
} |
766 |
0 |
else if ("".equals(value)) |
767 |
|
{ |
768 |
0 |
sb.append('<'); |
769 |
0 |
sb.append(key); |
770 |
0 |
sb.append("/>"); |
771 |
|
|
772 |
|
|
773 |
|
|
774 |
|
} |
775 |
|
else |
776 |
|
{ |
777 |
0 |
sb.append(toString(value, key)); |
778 |
|
} |
779 |
|
} |
780 |
0 |
if (tagName != null) |
781 |
|
{ |
782 |
|
|
783 |
|
|
784 |
0 |
sb.append("</"); |
785 |
0 |
sb.append(tagName); |
786 |
0 |
sb.append('>'); |
787 |
|
} |
788 |
0 |
return sb.toString(); |
789 |
|
|
790 |
|
} |
791 |
|
|
792 |
0 |
if (object != null |
793 |
|
&& (object instanceof JSONArray || object.getClass().isArray())) |
794 |
|
{ |
795 |
0 |
if (object.getClass().isArray()) |
796 |
|
{ |
797 |
0 |
ja = new JSONArray(object); |
798 |
|
} |
799 |
|
else |
800 |
|
{ |
801 |
0 |
ja = (JSONArray) object; |
802 |
|
} |
803 |
0 |
int jaLength = ja.length(); |
804 |
|
|
805 |
0 |
for (int i = 0; i < jaLength; i++) |
806 |
|
{ |
807 |
0 |
Object val = ja.opt(i); |
808 |
|
|
809 |
|
|
810 |
|
|
811 |
0 |
sb.append(toString(val, tagName == null ? "array" : tagName)); |
812 |
|
} |
813 |
0 |
return sb.toString(); |
814 |
|
} |
815 |
|
|
816 |
0 |
string = (object == null) ? "null" : escape(object.toString()); |
817 |
0 |
return (tagName == null) ? "\"" + string + "\"" |
818 |
0 |
: (string.length() == 0) ? "<" + tagName + "/>" |
819 |
|
: "<" + tagName + ">" + string + "</" + tagName + ">"; |
820 |
|
|
821 |
|
} |
822 |
|
} |