⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test.java

📁 JSON使用源码,对于AJAX与服务器数据交换,采用JSON作为数据传输格式是个不错的选择
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            j = XML.toJSONObject("<?xml version='1.0' encoding='UTF-8'?>"+"\n\n"+"<SOAP-ENV:Envelope"+              " xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\""+              " xmlns:xsi=\"http://www.w3.org/1999/XMLSchema-instance\""+              " xmlns:xsd=\"http://www.w3.org/1999/XMLSchema\">"+              "<SOAP-ENV:Body><ns1:doGoogleSearch"+              " xmlns:ns1=\"urn:GoogleSearch\""+              " SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">"+              "<key xsi:type=\"xsd:string\">GOOGLEKEY</key> <q"+              " xsi:type=\"xsd:string\">'+search+'</q> <start"+              " xsi:type=\"xsd:int\">0</start> <maxResults"+              " xsi:type=\"xsd:int\">10</maxResults> <filter"+              " xsi:type=\"xsd:boolean\">true</filter> <restrict"+              " xsi:type=\"xsd:string\"></restrict> <safeSearch"+              " xsi:type=\"xsd:boolean\">false</safeSearch> <lr"+              " xsi:type=\"xsd:string\"></lr> <ie"+              " xsi:type=\"xsd:string\">latin1</ie> <oe"+              " xsi:type=\"xsd:string\">latin1</oe>"+              "</ns1:doGoogleSearch>"+              "</SOAP-ENV:Body></SOAP-ENV:Envelope>");            System.out.println(j.toString(2));            System.out.println(XML.toString(j));            System.out.println("");            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\"}}}}");            System.out.println(j.toString(2));            System.out.println(XML.toString(j));            System.out.println("");            j = CookieList.toJSONObject("  f%oo = b+l=ah  ; o;n%40e = t.wo ");            System.out.println(j.toString(2));            System.out.println(CookieList.toString(j));            System.out.println("");            j = Cookie.toJSONObject("f%oo=blah; secure ;expires = April 24, 2002");            System.out.println(j.toString(2));            System.out.println(Cookie.toString(j));            System.out.println("");            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 /'}");            System.out.println(j.toString());            System.out.println("");            JSONTokener jt = new JSONTokener("{op:'test', to:'session', pre:1}{op:'test', to:'session', pre:2}");            j = new JSONObject(jt);            System.out.println(j.toString());            System.out.println("pre: " + j.optInt("pre"));            int i = jt.skipTo('{');            System.out.println(i);            j = new JSONObject(jt);            System.out.println(j.toString());            System.out.println("");            a = CDL.toJSONArray("No quotes, 'Single Quotes', \"Double Quotes\"\n1,'2',\"3\"\n,'It is \"good,\"', \"It works.\"\n\n");            System.out.println(CDL.toString(a));            System.out.println("");            System.out.println(a.toString(4));            System.out.println("");            a = new JSONArray(" [\"<escape>\", next is an implied null , , ok,] ");            System.out.println(a.toString());            System.out.println("");            System.out.println(XML.toString(a));            System.out.println("");            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. ; # comment\r oct=0666; hex=0x666; dec=666; o=0999; noh=0x0x}");            System.out.println(j.toString(4));            System.out.println("");            if (j.getBoolean("true") && !j.getBoolean("false")) {                System.out.println("It's all good");            }            System.out.println("");            j = new JSONObject(j, new String[]{"dec", "oct", "hex", "missing"});            System.out.println(j.toString(4));            System.out.println("");            System.out.println(new JSONStringer().array().value(a).value(j).endArray());            j = new JSONObject("{string: \"98.6\", long: 2147483648, int: 2147483647, longer: 9223372036854775807, double: 9223372036854775808}");            System.out.println(j.toString(4));            System.out.println("\ngetInt");            System.out.println("int    " + j.getInt("int"));            System.out.println("long   " + j.getInt("long"));            System.out.println("longer " + j.getInt("longer"));            System.out.println("double " + j.getInt("double"));            System.out.println("string " + j.getInt("string"));            System.out.println("\ngetLong");            System.out.println("int    " + j.getLong("int"));            System.out.println("long   " + j.getLong("long"));            System.out.println("longer " + j.getLong("longer"));            System.out.println("double " + j.getLong("double"));            System.out.println("string " + j.getLong("string"));            System.out.println("\ngetDouble");            System.out.println("int    " + j.getDouble("int"));            System.out.println("long   " + j.getDouble("long"));            System.out.println("longer " + j.getDouble("longer"));            System.out.println("double " + j.getDouble("double"));            System.out.println("string " + j.getDouble("string"));            j.put("good sized", 9223372036854775807L);            System.out.println(j.toString(4));            a = new JSONArray("[2147483647, 2147483648, 9223372036854775807, 9223372036854775808]");            System.out.println(a.toString(4));            System.out.println("\nKeys: ");            it = j.keys();            while (it.hasNext()) {                s = (String)it.next();                System.out.println(s + ": " + j.getString(s));            }            System.out.println("\naccumulate: ");            j = new JSONObject();            j.accumulate("stooge", "Curly");            j.accumulate("stooge", "Larry");            j.accumulate("stooge", "Moe");            a = j.getJSONArray("stooge");            a.put(5, "Shemp");            System.out.println(j.toString(4));            System.out.println("\nwrite:");            System.out.println(j.write(new StringWriter()));            s = "<xml empty><a></a><a>1</a><a>22</a><a>333</a></xml>";            j = XML.toJSONObject(s);            System.out.println(j.toString(4));            System.out.println(XML.toString(j));                        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>";            j = XML.toJSONObject(s);            System.out.println(j.toString(4));            System.out.println(XML.toString(j));                        Collection c = null;            Map m = null;                        j = new JSONObject(m);            a = new JSONArray(c);            j.append("stooge", "Joe DeRita");            j.append("stooge", "Shemp");            j.accumulate("stooges", "Curly");            j.accumulate("stooges", "Larry");            j.accumulate("stooges", "Moe");            j.accumulate("stoogearray", j.get("stooges"));            j.put("map", m);            j.put("collection", c);            j.put("array", a);            a.put(m);            a.put(c);            System.out.println(j.toString(4));                        System.out.println("\nTesting Exceptions: ");            System.out.print("Exception: ");            try {                System.out.println(j.getDouble("stooge"));            } catch (Exception e) {                System.out.println(e);            }            System.out.print("Exception: ");            try {                System.out.println(j.getDouble("howard"));            } catch (Exception e) {                System.out.println(e);            }            System.out.print("Exception: ");            try {                System.out.println(j.put(null, "howard"));            } catch (Exception e) {                System.out.println(e);            }            System.out.print("Exception: ");            try {                System.out.println(a.getDouble(0));            } catch (Exception e) {                System.out.println(e);            }            System.out.print("Exception: ");            try {                System.out.println(a.get(-1));            } catch (Exception e) {                System.out.println(e);            }            System.out.print("Exception: ");            try {                System.out.println(a.put(Double.NaN));            } catch (Exception e) {                System.out.println(e);            }            System.out.print("Exception: ");            try {            	j = XML.toJSONObject("<a><b>    ");            } catch (Exception e) {            	System.out.println(e);            }                        System.out.print("Exception: ");            try {            	j = XML.toJSONObject("<a></b>    ");            } catch (Exception e) {            	System.out.println(e);            }                        System.out.print("Exception: ");            try {            	j = XML.toJSONObject("<a></a    ");            } catch (Exception e) {            	System.out.println(e);            }        } catch (Exception e) {            System.out.println(e.toString());        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -