/connexion-json/src/org/json/Test.java
Java | 630 lines | 532 code | 84 blank | 14 comment | 3 complexity | 8ea53e13f71ba1339a5522d1b21f62c8 MD5 | raw file
1package org.json;
2
3import java.util.Collection;
4import java.util.Iterator;
5import java.util.Map;
6import java.io.StringWriter;
7
8/**
9 * Test class. This file is not formally a member of the org.json library.
10 * It is just a casual test tool.
11 */
12public class Test {
13
14 /**
15 * Entry point.
16 * @param args
17 */
18 public static void main(String args[]) {
19 Iterator it;
20 JSONArray a;
21 JSONObject j;
22 JSONStringer jj;
23 String s;
24
25/**
26 * Obj is a typical class that implements JSONString. It also
27 * provides some beanie methods that can be used to
28 * construct a JSONObject. It also demonstrates constructing
29 * a JSONObject with an array of names.
30 */
31 class Obj implements JSONString {
32 public String aString;
33 public double aNumber;
34 public boolean aBoolean;
35
36 public Obj(String string, double n, boolean b) {
37 this.aString = string;
38 this.aNumber = n;
39 this.aBoolean = b;
40 }
41
42 public double getNumber() {
43 return this.aNumber;
44 }
45
46 public String getString() {
47 return this.aString;
48 }
49
50 public boolean isBoolean() {
51 return this.aBoolean;
52 }
53
54 public String getBENT() {
55 return "All uppercase key";
56 }
57
58 public String getX() {
59 return "x";
60 }
61
62 public String toJSONString() {
63 return "{" + JSONObject.quote(this.aString) + ":" +
64 JSONObject.doubleToString(this.aNumber) + "}";
65 }
66 @Override
67 public String toString() {
68 return this.getString() + " " + this.getNumber() + " " +
69 this.isBoolean() + "." + this.getBENT() + " " + this.getX();
70 }
71 }
72
73
74 Obj obj = new Obj("A beany object", 42, true);
75
76 try {
77 j = XML.toJSONObject("<![CDATA[This is a collection of test patterns and examples for org.json.]]> Ignore the stuff past the end. ");
78 System.out.println(j.toString());
79
80 s = "{ \"list of lists\" : [ [1, 2, 3], [4, 5, 6], ] }";
81 j = new JSONObject(s);
82 System.out.println(j.toString(4));
83 System.out.println(XML.toString(j));
84
85 s = "<recipe name=\"bread\" prep_time=\"5 mins\" cook_time=\"3 hours\"> <title>Basic bread</title> <ingredient amount=\"8\" unit=\"dL\">Flour</ingredient> <ingredient amount=\"10\" unit=\"grams\">Yeast</ingredient> <ingredient amount=\"4\" unit=\"dL\" state=\"warm\">Water</ingredient> <ingredient amount=\"1\" unit=\"teaspoon\">Salt</ingredient> <instructions> <step>Mix all ingredients together.</step> <step>Knead thoroughly.</step> <step>Cover with a cloth, and leave for one hour in warm room.</step> <step>Knead again.</step> <step>Place in a bread baking tin.</step> <step>Cover with a cloth, and leave for one hour in warm room.</step> <step>Bake in the oven at 180(degrees)C for 30 minutes.</step> </instructions> </recipe> ";
86 j = XML.toJSONObject(s);
87 System.out.println(j.toString(4));
88 System.out.println();
89
90 j = JSONML.toJSONObject(s);
91 System.out.println(j.toString());
92 System.out.println(JSONML.toString(j));
93 System.out.println();
94
95 a = JSONML.toJSONArray(s);
96 System.out.println(a.toString(4));
97 System.out.println(JSONML.toString(a));
98 System.out.println();
99
100 s = "<div id=\"demo\" class=\"JSONML\"><p>JSONML is a transformation between <b>JSON</b> and <b>XML</b> that preserves ordering of document features.</p><p>JSONML can work with JSON arrays or JSON objects.</p><p>Three<br/>little<br/>words</p></div>";
101 j = JSONML.toJSONObject(s);
102 System.out.println(j.toString(4));
103 System.out.println(JSONML.toString(j));
104 System.out.println();
105
106 a = JSONML.toJSONArray(s);
107 System.out.println(a.toString(4));
108 System.out.println(JSONML.toString(a));
109 System.out.println();
110
111 s = "<person created=\"2006-11-11T19:23\" modified=\"2006-12-31T23:59\">\n <firstName>Robert</firstName>\n <lastName>Smith</lastName>\n <address type=\"home\">\n <street>12345 Sixth Ave</street>\n <city>Anytown</city>\n <state>CA</state>\n <postalCode>98765-4321</postalCode>\n </address>\n </person>";
112 j = XML.toJSONObject(s);
113 System.out.println(j.toString(4));
114
115 j = new JSONObject(obj);
116 System.out.println(j.toString());
117
118 s = "{ \"entity\": { \"imageURL\": \"\", \"name\": \"IXXXXXXXXXXXXX\", \"id\": 12336, \"ratingCount\": null, \"averageRating\": null } }";
119 j = new JSONObject(s);
120 System.out.println(j.toString(2));
121
122 jj = new JSONStringer();
123 s = jj
124 .object()
125 .key("single")
126 .value("MARIE HAA'S")
127 .key("Johnny")
128 .value("MARIE HAA\\'S")
129 .key("foo")
130 .value("bar")
131 .key("baz")
132 .array()
133 .object()
134 .key("quux")
135 .value("Thanks, Josh!")
136 .endObject()
137 .endArray()
138 .key("obj keys")
139 .value(JSONObject.getNames(obj))
140 .endObject()
141 .toString();
142 System.out.println(s);
143
144 System.out.println(new JSONStringer()
145 .object()
146 .key("a")
147 .array()
148 .array()
149 .array()
150 .value("b")
151 .endArray()
152 .endArray()
153 .endArray()
154 .endObject()
155 .toString());
156
157 jj = new JSONStringer();
158 jj.array();
159 jj.value(1);
160 jj.array();
161 jj.value(null);
162 jj.array();
163 jj.object();
164 jj.key("empty-array").array().endArray();
165 jj.key("answer").value(42);
166 jj.key("null").value(null);
167 jj.key("false").value(false);
168 jj.key("true").value(true);
169 jj.key("big").value(123456789e+88);
170 jj.key("small").value(123456789e-88);
171 jj.key("empty-object").object().endObject();
172 jj.key("long");
173 jj.value(9223372036854775807L);
174 jj.endObject();
175 jj.value("two");
176 jj.endArray();
177 jj.value(true);
178 jj.endArray();
179 jj.value(98.6);
180 jj.value(-100.0);
181 jj.object();
182 jj.endObject();
183 jj.object();
184 jj.key("one");
185 jj.value(1.00);
186 jj.endObject();
187 jj.value(obj);
188 jj.endArray();
189 System.out.println(jj.toString());
190
191 System.out.println(new JSONArray(jj.toString()).toString(4));
192
193 int ar[] = {1, 2, 3};
194 JSONArray ja = new JSONArray(ar);
195 System.out.println(ja.toString());
196
197 String sa[] = {"aString", "aNumber", "aBoolean"};
198 j = new JSONObject(obj, sa);
199 j.put("Testing JSONString interface", obj);
200 System.out.println(j.toString(4));
201
202 j = new JSONObject("{slashes: '///', closetag: '</script>', backslash:'\\\\', ei: {quotes: '\"\\''},eo: {a: '\"quoted\"', b:\"don't\"}, quotes: [\"'\", '\"']}");
203 System.out.println(j.toString(2));
204 System.out.println(XML.toString(j));
205 System.out.println("");
206
207 j = new JSONObject(
208 "{foo: [true, false,9876543210, 0.0, 1.00000001, 1.000000000001, 1.00000000000000001," +
209 " .00000000000000001, 2.00, 0.1, 2e100, -32,[],{}, \"string\"], " +
210 " to : null, op : 'Good'," +
211 "ten:10} postfix comment");
212 j.put("String", "98.6");
213 j.put("JSONObject", new JSONObject());
214 j.put("JSONArray", new JSONArray());
215 j.put("int", 57);
216 j.put("double", 123456789012345678901234567890.);
217 j.put("true", true);
218 j.put("false", false);
219 j.put("null", JSONObject.NULL);
220 j.put("bool", "true");
221 j.put("zero", -0.0);
222 j.put("\\u2028", "\u2028");
223 j.put("\\u2029", "\u2029");
224 a = j.getJSONArray("foo");
225 a.put(666);
226 a.put(2001.99);
227 a.put("so \"fine\".");
228 a.put("so <fine>.");
229 a.put(true);
230 a.put(false);
231 a.put(new JSONArray());
232 a.put(new JSONObject());
233 j.put("keys", JSONObject.getNames(j));
234 System.out.println(j.toString(4));
235 System.out.println(XML.toString(j));
236
237 System.out.println("String: " + j.getDouble("String"));
238 System.out.println(" bool: " + j.getBoolean("bool"));
239 System.out.println(" to: " + j.getString("to"));
240 System.out.println(" true: " + j.getString("true"));
241 System.out.println(" foo: " + j.getJSONArray("foo"));
242 System.out.println(" op: " + j.getString("op"));
243 System.out.println(" ten: " + j.getInt("ten"));
244 System.out.println(" oops: " + j.optBoolean("oops"));
245
246 s = "<xml one = 1 two=' \"2\" '><five></five>First \u0009<content><five></five> This is \"content\". <three> 3 </three>JSON does not preserve the sequencing of elements and contents.<three> III </three> <three> T H R E E</three><four/>Content text is an implied structure in XML. <six content=\"6\"/>JSON does not have implied structure:<seven>7</seven>everything is explicit.<![CDATA[CDATA blocks<are><supported>!]]></xml>";
247 j = XML.toJSONObject(s);
248 System.out.println(j.toString(2));
249 System.out.println(XML.toString(j));
250 System.out.println("");
251
252 ja = JSONML.toJSONArray(s);
253 System.out.println(ja.toString(4));
254 System.out.println(JSONML.toString(ja));
255 System.out.println("");
256
257 s = "<xml do='0'>uno<a re='1' mi='2'>dos<b fa='3'/>tres<c>true</c>quatro</a>cinqo<d>seis<e/></d></xml>";
258 ja = JSONML.toJSONArray(s);
259 System.out.println(ja.toString(4));
260 System.out.println(JSONML.toString(ja));
261 System.out.println("");
262
263 s = "<mapping><empty/> <class name = \"Customer\"> <field name = \"ID\" type = \"string\"> <bind-xml name=\"ID\" node=\"attribute\"/> </field> <field name = \"FirstName\" type = \"FirstName\"/> <field name = \"MI\" type = \"MI\"/> <field name = \"LastName\" type = \"LastName\"/> </class> <class name = \"FirstName\"> <field name = \"text\"> <bind-xml name = \"text\" node = \"text\"/> </field> </class> <class name = \"MI\"> <field name = \"text\"> <bind-xml name = \"text\" node = \"text\"/> </field> </class> <class name = \"LastName\"> <field name = \"text\"> <bind-xml name = \"text\" node = \"text\"/> </field> </class></mapping>";
264 j = XML.toJSONObject(s);
265
266 System.out.println(j.toString(2));
267 System.out.println(XML.toString(j));
268 System.out.println("");
269 ja = JSONML.toJSONArray(s);
270 System.out.println(ja.toString(4));
271 System.out.println(JSONML.toString(ja));
272 System.out.println("");
273
274 j = XML.toJSONObject("<?xml version=\"1.0\" ?><Book Author=\"Anonymous\"><Title>Sample Book</Title><Chapter id=\"1\">This is chapter 1. It is not very long or interesting.</Chapter><Chapter id=\"2\">This is chapter 2. Although it is longer than chapter 1, it is not any more interesting.</Chapter></Book>");
275 System.out.println(j.toString(2));
276 System.out.println(XML.toString(j));
277 System.out.println("");
278
279 j = XML.toJSONObject("<!DOCTYPE bCard 'http://www.cs.caltech.edu/~adam/schemas/bCard'><bCard><?xml default bCard firstname = '' lastname = '' company = '' email = '' homepage = ''?><bCard firstname = 'Rohit' lastname = 'Khare' company = 'MCI' email = 'khare@mci.net' homepage = 'http://pest.w3.org/'/><bCard firstname = 'Adam' lastname = 'Rifkin' company = 'Caltech Infospheres Project' email = 'adam@cs.caltech.edu' homepage = 'http://www.cs.caltech.edu/~adam/'/></bCard>");
280 System.out.println(j.toString(2));
281 System.out.println(XML.toString(j));
282 System.out.println("");
283
284 j = XML.toJSONObject("<?xml version=\"1.0\"?><customer> <firstName> <text>Fred</text> </firstName> <ID>fbs0001</ID> <lastName> <text>Scerbo</text> </lastName> <MI> <text>B</text> </MI></customer>");
285 System.out.println(j.toString(2));
286 System.out.println(XML.toString(j));
287 System.out.println("");
288
289 j = XML.toJSONObject("<!ENTITY tp-address PUBLIC '-//ABC University::Special Collections Library//TEXT (titlepage: name and address)//EN' 'tpspcoll.sgm'><list type='simple'><head>Repository Address </head><item>Special Collections Library</item><item>ABC University</item><item>Main Library, 40 Circle Drive</item><item>Ourtown, Pennsylvania</item><item>17654 USA</item></list>");
290 System.out.println(j.toString());
291 System.out.println(XML.toString(j));
292 System.out.println("");
293
294 j = XML.toJSONObject("<test intertag status=ok><empty/>deluxe<blip sweet=true>&"toot"&toot;A</blip><x>eks</x><w>bonus</w><w>bonus2</w></test>");
295 System.out.println(j.toString(2));
296 System.out.println(XML.toString(j));
297 System.out.println("");
298
299 j = HTTP.toJSONObject("GET / HTTP/1.0\nAccept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*\nAccept-Language: en-us\nUser-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; Win 9x 4.90; T312461; Q312461)\nHost: www.nokko.com\nConnection: keep-alive\nAccept-encoding: gzip, deflate\n");
300 System.out.println(j.toString(2));
301 System.out.println(HTTP.toString(j));
302 System.out.println("");
303
304 j = HTTP.toJSONObject("HTTP/1.1 200 Oki Doki\nDate: Sun, 26 May 2002 17:38:52 GMT\nServer: Apache/1.3.23 (Unix) mod_perl/1.26\nKeep-Alive: timeout=15, max=100\nConnection: Keep-Alive\nTransfer-Encoding: chunked\nContent-Type: text/html\n");
305 System.out.println(j.toString(2));
306 System.out.println(HTTP.toString(j));
307 System.out.println("");
308
309 j = new JSONObject("{nix: null, nux: false, null: 'null', 'Request-URI': '/', Method: 'GET', 'HTTP-Version': 'HTTP/1.0'}");
310 System.out.println(j.toString(2));
311 System.out.println("isNull: " + j.isNull("nix"));
312 System.out.println(" has: " + j.has("nix"));
313 System.out.println(XML.toString(j));
314 System.out.println(HTTP.toString(j));
315 System.out.println("");
316
317 j = XML.toJSONObject("<?xml version='1.0' encoding='UTF-8'?>"+"\n\n"+"<SOAP-ENV:Envelope"+
318 " xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\""+
319 " xmlns:xsi=\"http://www.w3.org/1999/XMLSchema-instance\""+
320 " xmlns:xsd=\"http://www.w3.org/1999/XMLSchema\">"+
321 "<SOAP-ENV:Body><ns1:doGoogleSearch"+
322 " xmlns:ns1=\"urn:GoogleSearch\""+
323 " SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"+
324 "<key xsi:type=\"xsd:string\">GOOGLEKEY</key> <q"+
325 " xsi:type=\"xsd:string\">'+search+'</q> <start"+
326 " xsi:type=\"xsd:int\">0</start> <maxResults"+
327 " xsi:type=\"xsd:int\">10</maxResults> <filter"+
328 " xsi:type=\"xsd:boolean\">true</filter> <restrict"+
329 " xsi:type=\"xsd:string\"></restrict> <safeSearch"+
330 " xsi:type=\"xsd:boolean\">false</safeSearch> <lr"+
331 " xsi:type=\"xsd:string\"></lr> <ie"+
332 " xsi:type=\"xsd:string\">latin1</ie> <oe"+
333 " xsi:type=\"xsd:string\">latin1</oe>"+
334 "</ns1:doGoogleSearch>"+
335 "</SOAP-ENV:Body></SOAP-ENV:Envelope>");
336 System.out.println(j.toString(2));
337 System.out.println(XML.toString(j));
338 System.out.println("");
339
340 j = new JSONObject("{Envelope: {Body: {\"ns1:doGoogleSearch\": {oe: \"latin1\", filter: true, q: \"'+search+'\", key: \"GOOGLEKEY\", maxResults: 10, \"SOAP-ENV:encodingStyle\": \"http://schemas.xmlsoap.org/soap/encoding/\", start: 0, ie: \"latin1\", safeSearch:false, \"xmlns:ns1\": \"urn:GoogleSearch\"}}}}");
341 System.out.println(j.toString(2));
342 System.out.println(XML.toString(j));
343 System.out.println("");
344
345 j = CookieList.toJSONObject(" f%oo = b+l=ah ; o;n%40e = t.wo ");
346 System.out.println(j.toString(2));
347 System.out.println(CookieList.toString(j));
348 System.out.println("");
349
350 j = Cookie.toJSONObject("f%oo=blah; secure ;expires = April 24, 2002");
351 System.out.println(j.toString(2));
352 System.out.println(Cookie.toString(j));
353 System.out.println("");
354
355 j = new JSONObject("{script: 'It is not allowed in HTML to send a close script tag in a string<script>because it confuses browsers</script>so we insert a backslash before the /'}");
356 System.out.println(j.toString());
357 System.out.println("");
358
359 JSONTokener jt = new JSONTokener("{op:'test', to:'session', pre:1}{op:'test', to:'session', pre:2}");
360 j = new JSONObject(jt);
361 System.out.println(j.toString());
362 System.out.println("pre: " + j.optInt("pre"));
363 int i = jt.skipTo('{');
364 System.out.println(i);
365 j = new JSONObject(jt);
366 System.out.println(j.toString());
367 System.out.println("");
368
369 a = CDL.toJSONArray("Comma delimited list test, '\"Strip\"Quotes', 'quote, comma', No quotes, 'Single Quotes', \"Double Quotes\"\n1,'2',\"3\"\n,'It is \"good,\"', \"It works.\"\n\n");
370
371 s = CDL.toString(a);
372 System.out.println(s);
373 System.out.println("");
374 System.out.println(a.toString(4));
375 System.out.println("");
376 a = CDL.toJSONArray(s);
377 System.out.println(a.toString(4));
378 System.out.println("");
379
380 a = new JSONArray(" [\"<escape>\", next is an implied null , , ok,] ");
381 System.out.println(a.toString());
382 System.out.println("");
383 System.out.println(XML.toString(a));
384 System.out.println("");
385
386 j = new JSONObject("{ fun => with non-standard forms ; forgiving => This package can be used to parse formats that are similar to but not stricting conforming to JSON; why=To make it easier to migrate existing data to JSON,one = [[1.00]]; uno=[[{1=>1}]];'+':+6e66 ;pluses=+++;empty = '' , 'double':0.666,true: TRUE, false: FALSE, null=NULL;[true] = [[!,@;*]]; string=> o. k. ; \r oct=0666; hex=0x666; dec=666; o=0999; noh=0x0x}");
387 System.out.println(j.toString(4));
388 System.out.println("");
389 if (j.getBoolean("true") && !j.getBoolean("false")) {
390 System.out.println("It's all good");
391 }
392
393 System.out.println("");
394 j = new JSONObject(j, new String[]{"dec", "oct", "hex", "missing"});
395 System.out.println(j.toString(4));
396
397 System.out.println("");
398 System.out.println(new JSONStringer().array().value(a).value(j).endArray());
399
400 j = new JSONObject("{string: \"98.6\", long: 2147483648, int: 2147483647, longer: 9223372036854775807, double: 9223372036854775808}");
401 System.out.println(j.toString(4));
402
403 System.out.println("\ngetInt");
404 System.out.println("int " + j.getInt("int"));
405 System.out.println("long " + j.getInt("long"));
406 System.out.println("longer " + j.getInt("longer"));
407 System.out.println("double " + j.getInt("double"));
408 System.out.println("string " + j.getInt("string"));
409
410 System.out.println("\ngetLong");
411 System.out.println("int " + j.getLong("int"));
412 System.out.println("long " + j.getLong("long"));
413 System.out.println("longer " + j.getLong("longer"));
414 System.out.println("double " + j.getLong("double"));
415 System.out.println("string " + j.getLong("string"));
416
417 System.out.println("\ngetDouble");
418 System.out.println("int " + j.getDouble("int"));
419 System.out.println("long " + j.getDouble("long"));
420 System.out.println("longer " + j.getDouble("longer"));
421 System.out.println("double " + j.getDouble("double"));
422 System.out.println("string " + j.getDouble("string"));
423
424 j.put("good sized", 9223372036854775807L);
425 System.out.println(j.toString(4));
426
427 a = new JSONArray("[2147483647, 2147483648, 9223372036854775807, 9223372036854775808]");
428 System.out.println(a.toString(4));
429
430 System.out.println("\nKeys: ");
431 it = j.keys();
432 while (it.hasNext()) {
433 s = (String)it.next();
434 System.out.println(s + ": " + j.getString(s));
435 }
436
437
438 System.out.println("\naccumulate: ");
439 j = new JSONObject();
440 j.accumulate("stooge", "Curly");
441 j.accumulate("stooge", "Larry");
442 j.accumulate("stooge", "Moe");
443 a = j.getJSONArray("stooge");
444 a.put(5, "Shemp");
445 System.out.println(j.toString(4));
446
447 System.out.println("\nwrite:");
448 System.out.println(j.write(new StringWriter()));
449
450 s = "<xml empty><a></a><a>1</a><a>22</a><a>333</a></xml>";
451 j = XML.toJSONObject(s);
452 System.out.println(j.toString(4));
453 System.out.println(XML.toString(j));
454
455 s = "<book><chapter>Content of the first chapter</chapter><chapter>Content of the second chapter <chapter>Content of the first subchapter</chapter> <chapter>Content of the second subchapter</chapter></chapter><chapter>Third Chapter</chapter></book>";
456 j = XML.toJSONObject(s);
457 System.out.println(j.toString(4));
458 System.out.println(XML.toString(j));
459
460 a = JSONML.toJSONArray(s);
461 System.out.println(a.toString(4));
462 System.out.println(JSONML.toString(a));
463
464 Collection c = null;
465 Map m = null;
466
467 j = new JSONObject(m);
468 a = new JSONArray(c);
469 j.append("stooge", "Joe DeRita");
470 j.append("stooge", "Shemp");
471 j.accumulate("stooges", "Curly");
472 j.accumulate("stooges", "Larry");
473 j.accumulate("stooges", "Moe");
474 j.accumulate("stoogearray", j.get("stooges"));
475 j.put("map", m);
476 j.put("collection", c);
477 j.put("array", a);
478 a.put(m);
479 a.put(c);
480 System.out.println(j.toString(4));
481
482 s = "{plist=Apple; AnimalSmells = { pig = piggish; lamb = lambish; worm = wormy; }; AnimalSounds = { pig = oink; lamb = baa; worm = baa; Lisa = \"Why is the worm talking like a lamb?\" } ; AnimalColors = { pig = pink; lamb = black; worm = pink; } } ";
483 j = new JSONObject(s);
484 System.out.println(j.toString(4));
485
486 s = " (\"San Francisco\", \"New York\", \"Seoul\", \"London\", \"Seattle\", \"Shanghai\")";
487 a = new JSONArray(s);
488 System.out.println(a.toString());
489
490 s = "<a ichi='1' ni='2'><b>The content of b</b> and <c san='3'>The content of c</c><d>do</d><e></e><d>re</d><f/><d>mi</d></a>";
491 j = XML.toJSONObject(s);
492
493 System.out.println(j.toString(2));
494 System.out.println(XML.toString(j));
495 System.out.println("");
496 ja = JSONML.toJSONArray(s);
497 System.out.println(ja.toString(4));
498 System.out.println(JSONML.toString(ja));
499 System.out.println("");
500
501
502 System.out.println("\nTesting Exceptions: ");
503
504 System.out.print("Exception: ");
505 try {
506 a = new JSONArray();
507 a.put(Double.NEGATIVE_INFINITY);
508 a.put(Double.NaN);
509 System.out.println(a.toString());
510 } catch (Exception e) {
511 System.out.println(e);
512 }
513 System.out.print("Exception: ");
514 try {
515 System.out.println(j.getDouble("stooge"));
516 } catch (Exception e) {
517 System.out.println(e);
518 }
519 System.out.print("Exception: ");
520 try {
521 System.out.println(j.getDouble("howard"));
522 } catch (Exception e) {
523 System.out.println(e);
524 }
525 System.out.print("Exception: ");
526 try {
527 System.out.println(j.put(null, "howard"));
528 } catch (Exception e) {
529 System.out.println(e);
530 }
531 System.out.print("Exception: ");
532 try {
533 System.out.println(a.getDouble(0));
534 } catch (Exception e) {
535 System.out.println(e);
536 }
537 System.out.print("Exception: ");
538 try {
539 System.out.println(a.get(-1));
540 } catch (Exception e) {
541 System.out.println(e);
542 }
543 System.out.print("Exception: ");
544 try {
545 System.out.println(a.put(Double.NaN));
546 } catch (Exception e) {
547 System.out.println(e);
548 }
549 System.out.print("Exception: ");
550 try {
551 j = XML.toJSONObject("<a><b> ");
552 } catch (Exception e) {
553 System.out.println(e);
554 }
555 System.out.print("Exception: ");
556 try {
557 j = XML.toJSONObject("<a></b> ");
558 } catch (Exception e) {
559 System.out.println(e);
560 }
561 System.out.print("Exception: ");
562 try {
563 j = XML.toJSONObject("<a></a ");
564 } catch (Exception e) {
565 System.out.println(e);
566 }
567 System.out.print("Exception: ");
568 try {
569 ja = new JSONArray(new Object());
570 System.out.println(ja.toString());
571 } catch (Exception e) {
572 System.out.println(e);
573 }
574
575 System.out.print("Exception: ");
576 try {
577 s = "[)";
578 a = new JSONArray(s);
579 System.out.println(a.toString());
580 } catch (Exception e) {
581 System.out.println(e);
582 }
583
584 System.out.print("Exception: ");
585 try {
586 s = "<xml";
587 ja = JSONML.toJSONArray(s);
588 System.out.println(ja.toString(4));
589 } catch (Exception e) {
590 System.out.println(e);
591 }
592
593 System.out.print("Exception: ");
594 try {
595 s = "<right></wrong>";
596 ja = JSONML.toJSONArray(s);
597 System.out.println(ja.toString(4));
598 } catch (Exception e) {
599 System.out.println(e);
600 }
601
602 System.out.print("Exception: ");
603 try {
604 s = "{\"koda\": true, \"koda\": true}";
605 j = new JSONObject(s);
606 System.out.println(j.toString(4));
607 } catch (Exception e) {
608 System.out.println(e);
609 }
610
611 System.out.print("Exception: ");
612 try {
613 jj = new JSONStringer();
614 s = jj
615 .object()
616 .key("bosanda")
617 .value("MARIE HAA'S")
618 .key("bosanda")
619 .value("MARIE HAA\\'S")
620 .endObject()
621 .toString();
622 System.out.println(j.toString(4));
623 } catch (Exception e) {
624 System.out.println(e);
625 }
626 } catch (Exception e) {
627 System.out.println(e.toString());
628 }
629 }
630}