Test.java
上传用户:cdpainuo
上传日期:2022-07-12
资源大小:5257k
文件大小:29k
源码类别:

Jsp/Servlet

开发平台:

Java

  1. package org.json;
  2. import java.util.Collection;
  3. import java.util.Iterator;
  4. import java.util.Map;
  5. import java.io.StringWriter;
  6. /**
  7.  * Test class. This file is not formally a member of the org.json library.
  8.  * It is just a casual test tool.
  9.  */
  10. public class Test {
  11.     /**
  12.      * Entry point.
  13.      * @param args
  14.      */
  15.     public static void main(String args[]) {
  16.         Iterator it;
  17.         JSONArray a;
  18.         JSONObject j;
  19.         JSONStringer jj;
  20.         String s;
  21.         
  22. /** 
  23.  *  Obj is a typical class that implements JSONString. It also
  24.  *  provides some beanie methods that can be used to 
  25.  *  construct a JSONObject. It also demonstrates constructing
  26.  *  a JSONObject with an array of names.
  27.  */
  28.         class Obj implements JSONString {
  29.          public String aString;
  30.          public double aNumber;
  31.          public boolean aBoolean;
  32.         
  33.             public Obj(String string, double n, boolean b) {
  34.                 this.aString = string;
  35.                 this.aNumber = n;
  36.                 this.aBoolean = b;
  37.             }
  38.             
  39.             public double getNumber() {
  40.              return this.aNumber;
  41.             }
  42.             
  43.             public String getString() {
  44.              return this.aString;
  45.             }
  46.             
  47.             public boolean isBoolean() {
  48.              return this.aBoolean;
  49.             }
  50.             
  51.             public String getBENT() {
  52.              return "All uppercase key";
  53.             }
  54.             
  55.             public String getX() {
  56.              return "x";
  57.             }
  58.             
  59.             public String toJSONString() {
  60.              return "{" + JSONObject.quote(this.aString) + ":" + 
  61.              JSONObject.doubleToString(this.aNumber) + "}";
  62.             }            
  63.             public String toString() {
  64.              return this.getString() + " " + this.getNumber() + " " + 
  65.              this.isBoolean() + "." + this.getBENT() + " " + this.getX();
  66.             }
  67.         }      
  68.         
  69.      Obj obj = new Obj("A beany object", 42, true);
  70.         
  71.         try {     
  72.             j = XML.toJSONObject("<![CDATA[This is a collection of test patterns and examples for org.json.]]>  Ignore the stuff past the end.  ");
  73.             System.out.println(j.toString());
  74.             s = "{     "list of lists" : [         [1, 2, 3],         [4, 5, 6],     ] }";
  75.             j = new JSONObject(s);
  76.             System.out.println(j.toString(4));
  77.             System.out.println(XML.toString(j));
  78.                     
  79.             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> ";
  80.             j = XML.toJSONObject(s);
  81.             System.out.println(j.toString(4));
  82.             System.out.println();
  83.             
  84.             j = JSONML.toJSONObject(s);
  85.             System.out.println(j.toString());
  86.             System.out.println(JSONML.toString(j));
  87.             System.out.println();
  88.             
  89.             a = JSONML.toJSONArray(s);
  90.             System.out.println(a.toString(4));
  91.             System.out.println(JSONML.toString(a));
  92.             System.out.println();
  93.             
  94.             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>";
  95.             j = JSONML.toJSONObject(s);
  96.             System.out.println(j.toString(4));
  97.             System.out.println(JSONML.toString(j));
  98.             System.out.println();
  99.             
  100.             a = JSONML.toJSONArray(s);
  101.             System.out.println(a.toString(4));
  102.             System.out.println(JSONML.toString(a));
  103.             System.out.println();
  104.             
  105.             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>";
  106.             j = XML.toJSONObject(s);
  107.             System.out.println(j.toString(4));
  108.             
  109.             j = new JSONObject(obj);
  110.             System.out.println(j.toString());
  111.             
  112.             s = "{ "entity": { "imageURL": "", "name": "IXXXXXXXXXXXXX", "id": 12336, "ratingCount": null, "averageRating": null } }";
  113.             j = new JSONObject(s);
  114.             System.out.println(j.toString(2));
  115.             jj = new JSONStringer();
  116.             s = jj
  117.             .object()
  118.                 .key("single")
  119.                 .value("MARIE HAA'S")
  120.                 .key("Johnny")
  121.                 .value("MARIE HAA\'S")
  122.                 .key("foo")
  123.                 .value("bar")
  124.                 .key("baz")
  125.                 .array()
  126.                     .object()
  127.                         .key("quux")
  128.                         .value("Thanks, Josh!")
  129.                     .endObject()
  130.                 .endArray()
  131.                 .key("obj keys")
  132.                 .value(JSONObject.getNames(obj))
  133.             .endObject()
  134.             .toString();
  135.             System.out.println(s);
  136.             System.out.println(new JSONStringer()
  137.                 .object()
  138.                  .key("a")
  139.                  .array()
  140.                  .array()
  141.                  .array()
  142.                  .value("b")
  143.                             .endArray()
  144.                         .endArray()
  145.                     .endArray()
  146.                 .endObject()
  147.                 .toString());
  148.             jj = new JSONStringer();
  149.             jj.array();
  150.             jj.value(1);
  151.             jj.array();
  152.             jj.value(null);
  153.             jj.array();
  154.             jj.object();
  155.             jj.key("empty-array").array().endArray();
  156.             jj.key("answer").value(42);
  157.             jj.key("null").value(null);
  158.             jj.key("false").value(false);
  159.             jj.key("true").value(true);
  160.             jj.key("big").value(123456789e+88);
  161.             jj.key("small").value(123456789e-88);
  162.             jj.key("empty-object").object().endObject();
  163.             jj.key("long");
  164.             jj.value(9223372036854775807L);
  165.             jj.endObject();
  166.             jj.value("two");
  167.             jj.endArray();
  168.             jj.value(true);
  169.             jj.endArray();
  170.             jj.value(98.6);
  171.             jj.value(-100.0);
  172.             jj.object();
  173.             jj.endObject();
  174.             jj.object();
  175.             jj.key("one");
  176.             jj.value(1.00);
  177.             jj.endObject();
  178.             jj.value(obj);
  179.             jj.endArray();
  180.             System.out.println(jj.toString());
  181.             System.out.println(new JSONArray(jj.toString()).toString(4));
  182.          int ar[] = {1, 2, 3};
  183.          JSONArray ja = new JSONArray(ar);
  184.          System.out.println(ja.toString());
  185.         
  186.          String sa[] = {"aString", "aNumber", "aBoolean"};            
  187.             j = new JSONObject(obj, sa);
  188.             j.put("Testing JSONString interface", obj);
  189.             System.out.println(j.toString(4));          
  190.             
  191.             j = new JSONObject("{slashes: '///', closetag: '</script>', backslash:'\\', ei: {quotes: '"\''},eo: {a: '"quoted"', b:"don't"}, quotes: ["'", '"']}");
  192.             System.out.println(j.toString(2));
  193.             System.out.println(XML.toString(j));
  194.             System.out.println("");
  195.             j = new JSONObject(
  196.                 "{foo: [true, false,9876543210,    0.0, 1.00000001,  1.000000000001, 1.00000000000000001," +
  197.                 " .00000000000000001, 2.00, 0.1, 2e100, -32,[],{}, "string"], " +
  198.                 "  to   : null, op : 'Good'," +
  199.                 "ten:10} postfix comment");
  200.             j.put("String", "98.6");
  201.             j.put("JSONObject", new JSONObject());
  202.             j.put("JSONArray", new JSONArray());
  203.             j.put("int", 57);
  204.             j.put("double", 123456789012345678901234567890.);
  205.             j.put("true", true);
  206.             j.put("false", false);
  207.             j.put("null", JSONObject.NULL);
  208.             j.put("bool", "true");
  209.             j.put("zero", -0.0);
  210.             j.put("\u2028", "u2028");
  211.             j.put("\u2029", "u2029");
  212.             a = j.getJSONArray("foo");
  213.             a.put(666);
  214.             a.put(2001.99);
  215.             a.put("so "fine".");
  216.             a.put("so <fine>.");
  217.             a.put(true);
  218.             a.put(false);
  219.             a.put(new JSONArray());
  220.             a.put(new JSONObject());
  221.             j.put("keys", JSONObject.getNames(j));
  222.             System.out.println(j.toString(4));
  223.             System.out.println(XML.toString(j));
  224.             System.out.println("String: " + j.getDouble("String"));
  225.             System.out.println("  bool: " + j.getBoolean("bool"));
  226.             System.out.println("    to: " + j.getString("to"));
  227.             System.out.println("  true: " + j.getString("true"));
  228.             System.out.println("   foo: " + j.getJSONArray("foo"));
  229.             System.out.println("    op: " + j.getString("op"));
  230.             System.out.println("   ten: " + j.getInt("ten"));
  231.             System.out.println("  oops: " + j.optBoolean("oops"));
  232.             s = "<xml one = 1 two=' "2" '><five></five>First u0009&lt;content&gt;<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>";
  233.             j = XML.toJSONObject(s);
  234.             System.out.println(j.toString(2));
  235.             System.out.println(XML.toString(j));
  236.             System.out.println("");
  237.             
  238.             ja = JSONML.toJSONArray(s);
  239.             System.out.println(ja.toString(4));
  240.             System.out.println(JSONML.toString(ja));
  241.             System.out.println("");
  242.             
  243.             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>";
  244.             ja = JSONML.toJSONArray(s);
  245.             System.out.println(ja.toString(4));
  246.             System.out.println(JSONML.toString(ja));
  247.             System.out.println("");
  248.             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>";
  249.             j = XML.toJSONObject(s);
  250.             System.out.println(j.toString(2));
  251.             System.out.println(XML.toString(j));
  252.             System.out.println("");
  253.             ja = JSONML.toJSONArray(s);
  254.             System.out.println(ja.toString(4));
  255.             System.out.println(JSONML.toString(ja));
  256.             System.out.println("");
  257.             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>");
  258.             System.out.println(j.toString(2));
  259.             System.out.println(XML.toString(j));
  260.             System.out.println("");
  261.             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>");
  262.             System.out.println(j.toString(2));
  263.             System.out.println(XML.toString(j));
  264.             System.out.println("");
  265.             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>");
  266.             System.out.println(j.toString(2));
  267.             System.out.println(XML.toString(j));
  268.             System.out.println("");
  269.             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>");
  270.             System.out.println(j.toString());
  271.             System.out.println(XML.toString(j));
  272.             System.out.println("");
  273.             j = XML.toJSONObject("<test intertag status=ok><empty/>deluxe<blip sweet=true>&amp;&quot;toot&quot;&toot;&#x41;</blip><x>eks</x><w>bonus</w><w>bonus2</w></test>");
  274.             System.out.println(j.toString(2));
  275.             System.out.println(XML.toString(j));
  276.             System.out.println("");
  277.             j = HTTP.toJSONObject("GET / HTTP/1.0nAccept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-powerpoint, application/vnd.ms-excel, application/msword, */*nAccept-Language: en-usnUser-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; Win 9x 4.90; T312461; Q312461)nHost: www.nokko.comnConnection: keep-alivenAccept-encoding: gzip, deflaten");
  278.             System.out.println(j.toString(2));
  279.             System.out.println(HTTP.toString(j));
  280.             System.out.println("");
  281.             j = HTTP.toJSONObject("HTTP/1.1 200 Oki DokinDate: Sun, 26 May 2002 17:38:52 GMTnServer: Apache/1.3.23 (Unix) mod_perl/1.26nKeep-Alive: timeout=15, max=100nConnection: Keep-AlivenTransfer-Encoding: chunkednContent-Type: text/htmln");
  282.             System.out.println(j.toString(2));
  283.             System.out.println(HTTP.toString(j));
  284.             System.out.println("");
  285.             j = new JSONObject("{nix: null, nux: false, null: 'null', 'Request-URI': '/', Method: 'GET', 'HTTP-Version': 'HTTP/1.0'}");
  286.             System.out.println(j.toString(2));
  287.             System.out.println("isNull: " + j.isNull("nix"));
  288.             System.out.println("   has: " + j.has("nix"));
  289.             System.out.println(XML.toString(j));
  290.             System.out.println(HTTP.toString(j));
  291.             System.out.println("");
  292.             j = XML.toJSONObject("<?xml version='1.0' encoding='UTF-8'?>"+"nn"+"<SOAP-ENV:Envelope"+
  293.               " xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/""+
  294.               " xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance""+
  295.               " xmlns:xsd="http://www.w3.org/1999/XMLSchema">"+
  296.               "<SOAP-ENV:Body><ns1:doGoogleSearch"+
  297.               " xmlns:ns1="urn:GoogleSearch""+
  298.               " SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">"+
  299.               "<key xsi:type="xsd:string">GOOGLEKEY</key> <q"+
  300.               " xsi:type="xsd:string">'+search+'</q> <start"+
  301.               " xsi:type="xsd:int">0</start> <maxResults"+
  302.               " xsi:type="xsd:int">10</maxResults> <filter"+
  303.               " xsi:type="xsd:boolean">true</filter> <restrict"+
  304.               " xsi:type="xsd:string"></restrict> <safeSearch"+
  305.               " xsi:type="xsd:boolean">false</safeSearch> <lr"+
  306.               " xsi:type="xsd:string"></lr> <ie"+
  307.               " xsi:type="xsd:string">latin1</ie> <oe"+
  308.               " xsi:type="xsd:string">latin1</oe>"+
  309.               "</ns1:doGoogleSearch>"+
  310.               "</SOAP-ENV:Body></SOAP-ENV:Envelope>");
  311.             System.out.println(j.toString(2));
  312.             System.out.println(XML.toString(j));
  313.             System.out.println("");
  314.             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"}}}}");
  315.             System.out.println(j.toString(2));
  316.             System.out.println(XML.toString(j));
  317.             System.out.println("");
  318.             j = CookieList.toJSONObject("  f%oo = b+l=ah  ; o;n%40e = t.wo ");
  319.             System.out.println(j.toString(2));
  320.             System.out.println(CookieList.toString(j));
  321.             System.out.println("");
  322.             j = Cookie.toJSONObject("f%oo=blah; secure ;expires = April 24, 2002");
  323.             System.out.println(j.toString(2));
  324.             System.out.println(Cookie.toString(j));
  325.             System.out.println("");
  326.             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 /'}");
  327.             System.out.println(j.toString());
  328.             System.out.println("");
  329.             JSONTokener jt = new JSONTokener("{op:'test', to:'session', pre:1}{op:'test', to:'session', pre:2}");
  330.             j = new JSONObject(jt);
  331.             System.out.println(j.toString());
  332.             System.out.println("pre: " + j.optInt("pre"));
  333.             int i = jt.skipTo('{');
  334.             System.out.println(i);
  335.             j = new JSONObject(jt);
  336.             System.out.println(j.toString());
  337.             System.out.println("");
  338.             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."nn");
  339.             s = CDL.toString(a);
  340.             System.out.println(s);
  341.             System.out.println("");
  342.             System.out.println(a.toString(4));
  343.             System.out.println("");
  344.             a = CDL.toJSONArray(s);
  345.             System.out.println(a.toString(4));
  346.             System.out.println("");
  347.             a = new JSONArray(" ["<escape>", next is an implied null , , ok,] ");
  348.             System.out.println(a.toString());
  349.             System.out.println("");
  350.             System.out.println(XML.toString(a));
  351.             System.out.println("");
  352.             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}");
  353.             System.out.println(j.toString(4));
  354.             System.out.println("");
  355.             if (j.getBoolean("true") && !j.getBoolean("false")) {
  356.                 System.out.println("It's all good");
  357.             }
  358.             System.out.println("");
  359.             j = new JSONObject(j, new String[]{"dec", "oct", "hex", "missing"});
  360.             System.out.println(j.toString(4));
  361.             System.out.println("");
  362.             System.out.println(new JSONStringer().array().value(a).value(j).endArray());
  363.             j = new JSONObject("{string: "98.6", long: 2147483648, int: 2147483647, longer: 9223372036854775807, double: 9223372036854775808}");
  364.             System.out.println(j.toString(4));
  365.             System.out.println("ngetInt");
  366.             System.out.println("int    " + j.getInt("int"));
  367.             System.out.println("long   " + j.getInt("long"));
  368.             System.out.println("longer " + j.getInt("longer"));
  369.             System.out.println("double " + j.getInt("double"));
  370.             System.out.println("string " + j.getInt("string"));
  371.             System.out.println("ngetLong");
  372.             System.out.println("int    " + j.getLong("int"));
  373.             System.out.println("long   " + j.getLong("long"));
  374.             System.out.println("longer " + j.getLong("longer"));
  375.             System.out.println("double " + j.getLong("double"));
  376.             System.out.println("string " + j.getLong("string"));
  377.             System.out.println("ngetDouble");
  378.             System.out.println("int    " + j.getDouble("int"));
  379.             System.out.println("long   " + j.getDouble("long"));
  380.             System.out.println("longer " + j.getDouble("longer"));
  381.             System.out.println("double " + j.getDouble("double"));
  382.             System.out.println("string " + j.getDouble("string"));
  383.             j.put("good sized", 9223372036854775807L);
  384.             System.out.println(j.toString(4));
  385.             a = new JSONArray("[2147483647, 2147483648, 9223372036854775807, 9223372036854775808]");
  386.             System.out.println(a.toString(4));
  387.             System.out.println("nKeys: ");
  388.             it = j.keys();
  389.             while (it.hasNext()) {
  390.                 s = (String)it.next();
  391.                 System.out.println(s + ": " + j.getString(s));
  392.             }
  393.             System.out.println("naccumulate: ");
  394.             j = new JSONObject();
  395.             j.accumulate("stooge", "Curly");
  396.             j.accumulate("stooge", "Larry");
  397.             j.accumulate("stooge", "Moe");
  398.             a = j.getJSONArray("stooge");
  399.             a.put(5, "Shemp");
  400.             System.out.println(j.toString(4));
  401.             System.out.println("nwrite:");
  402.             System.out.println(j.write(new StringWriter()));
  403.             s = "<xml empty><a></a><a>1</a><a>22</a><a>333</a></xml>";
  404.             j = XML.toJSONObject(s);
  405.             System.out.println(j.toString(4));
  406.             System.out.println(XML.toString(j));
  407.             
  408.             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>";
  409.             j = XML.toJSONObject(s);
  410.             System.out.println(j.toString(4));
  411.             System.out.println(XML.toString(j));
  412.             
  413.             a = JSONML.toJSONArray(s);
  414.             System.out.println(a.toString(4));
  415.             System.out.println(JSONML.toString(a));
  416.             
  417.             Collection c = null;
  418.             Map m = null;
  419.             
  420.             j = new JSONObject(m);
  421.             a = new JSONArray(c);
  422.             j.append("stooge", "Joe DeRita");
  423.             j.append("stooge", "Shemp");
  424.             j.accumulate("stooges", "Curly");
  425.             j.accumulate("stooges", "Larry");
  426.             j.accumulate("stooges", "Moe");
  427.             j.accumulate("stoogearray", j.get("stooges"));
  428.             j.put("map", m);
  429.             j.put("collection", c);
  430.             j.put("array", a);
  431.             a.put(m);
  432.             a.put(c);
  433.             System.out.println(j.toString(4));
  434.             
  435.             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; } } "; 
  436.             j = new JSONObject(s);
  437.             System.out.println(j.toString(4));
  438.             
  439.             s = " ("San Francisco", "New York", "Seoul", "London", "Seattle", "Shanghai")";
  440.             a = new JSONArray(s);
  441.             System.out.println(a.toString());
  442.             
  443.             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>";
  444.             j = XML.toJSONObject(s);
  445.             System.out.println(j.toString(2));
  446.             System.out.println(XML.toString(j));
  447.             System.out.println("");
  448.             ja = JSONML.toJSONArray(s);
  449.             System.out.println(ja.toString(4));
  450.             System.out.println(JSONML.toString(ja));
  451.             System.out.println("");
  452.           
  453.             
  454.             System.out.println("nTesting Exceptions: ");
  455.             System.out.print("Exception: ");
  456.             try {
  457.                 a = new JSONArray();
  458.                 a.put(Double.NEGATIVE_INFINITY);
  459.                 a.put(Double.NaN);
  460.                 System.out.println(a.toString());
  461.             } catch (Exception e) {
  462.                 System.out.println(e);
  463.             }
  464.             System.out.print("Exception: ");
  465.             try {
  466.                 System.out.println(j.getDouble("stooge"));
  467.             } catch (Exception e) {
  468.                 System.out.println(e);
  469.             }
  470.             System.out.print("Exception: ");
  471.             try {
  472.                 System.out.println(j.getDouble("howard"));
  473.             } catch (Exception e) {
  474.                 System.out.println(e);
  475.             }
  476.             System.out.print("Exception: ");
  477.             try {
  478.                 System.out.println(j.put(null, "howard"));
  479.             } catch (Exception e) {
  480.                 System.out.println(e);
  481.             }
  482.             System.out.print("Exception: ");
  483.             try {
  484.                 System.out.println(a.getDouble(0));
  485.             } catch (Exception e) {
  486.                 System.out.println(e);
  487.             }
  488.             System.out.print("Exception: ");
  489.             try {
  490.                 System.out.println(a.get(-1));
  491.             } catch (Exception e) {
  492.                 System.out.println(e);
  493.             }
  494.             System.out.print("Exception: ");
  495.             try {
  496.                 System.out.println(a.put(Double.NaN));
  497.             } catch (Exception e) {
  498.                 System.out.println(e);
  499.             }
  500.             System.out.print("Exception: ");
  501.             try {
  502.              j = XML.toJSONObject("<a><b>    ");
  503.             } catch (Exception e) {
  504.              System.out.println(e);
  505.             }            
  506.             System.out.print("Exception: ");
  507.             try {
  508.              j = XML.toJSONObject("<a></b>    ");
  509.             } catch (Exception e) {
  510.              System.out.println(e);
  511.             }            
  512.             System.out.print("Exception: ");
  513.             try {
  514.              j = XML.toJSONObject("<a></a    ");
  515.             } catch (Exception e) {
  516.              System.out.println(e);
  517.             }
  518.             System.out.print("Exception: ");
  519.             try {            
  520.              ja = new JSONArray(new Object());
  521.              System.out.println(ja.toString());
  522.             } catch (Exception e) {
  523.              System.out.println(e);
  524.             }
  525.             System.out.print("Exception: ");
  526.             try {            
  527.              s = "[)";
  528.              a = new JSONArray(s);
  529.              System.out.println(a.toString());
  530.             } catch (Exception e) {
  531.              System.out.println(e);
  532.             }
  533.             System.out.print("Exception: ");
  534.             try {            
  535.                 s = "<xml";
  536.                 ja = JSONML.toJSONArray(s);
  537.                 System.out.println(ja.toString(4));
  538.             } catch (Exception e) {
  539.              System.out.println(e);
  540.             }
  541.             System.out.print("Exception: ");
  542.             try {            
  543.                 s = "<right></wrong>";
  544.                 ja = JSONML.toJSONArray(s);
  545.                 System.out.println(ja.toString(4));
  546.             } catch (Exception e) {
  547.              System.out.println(e);
  548.             }
  549.             System.out.print("Exception: ");
  550.             try {            
  551.                 s = "{"koda": true, "koda": true}";
  552.                 j = new JSONObject(s);
  553.                 System.out.println(j.toString(4));
  554.             } catch (Exception e) {
  555.              System.out.println(e);
  556.             }
  557.             System.out.print("Exception: ");
  558.             try {            
  559.                 jj = new JSONStringer();
  560.                 s = jj
  561.                  .object()
  562.                      .key("bosanda")
  563.                      .value("MARIE HAA'S")
  564.                      .key("bosanda")
  565.                      .value("MARIE HAA\'S")
  566.                  .endObject()
  567.                  .toString();
  568.                 System.out.println(j.toString(4));
  569.             } catch (Exception e) {
  570.              System.out.println(e);
  571.             }
  572.         } catch (Exception e) {
  573.             System.out.println(e.toString());
  574.         }
  575.     }
  576. }