| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,7 +32,7 @@ of this software and associated documentation files (the "Software"), to deal | |||
| 32 | 32 | * JSONObject, and to covert a JSONArray or JSONObject into an XML text using | |
| 33 | 33 | * the JsonML transform. | |
| 34 | 34 | * @author JSON.org | |
| 35 | - * @version 2010-12-23 | ||
| 35 | + * @version 2011-10-03 | ||
| 36 | 36 | */ | |
| 37 | 37 | public class JSONML { | |
| 38 | 38 | ||
@@ -45,8 +45,11 @@ public class JSONML { | |||
| 45 | 45 | * @return A JSONArray if the value is the outermost tag, otherwise null. | |
| 46 | 46 | * @throws JSONException | |
| 47 | 47 | */ | |
| 48 | - private static Object parse(XMLTokener x, boolean arrayForm, | ||
| 49 | - JSONArray ja) throws JSONException { | ||
| 48 | + private static Object parse( | ||
| 49 | + XMLTokener x, | ||
| 50 | + boolean arrayForm, | ||
| 51 | + JSONArray ja | ||
| 52 | + ) throws JSONException { | ||
| 50 | 53 | String attribute; | |
| 51 | 54 | char c; | |
| 52 | 55 | String closeTag = null; | |
@@ -439,8 +442,10 @@ public static String toString(JSONObject jo) throws JSONException { | |||
| 439 | 442 | if (object != null) { | |
| 440 | 443 | if (object instanceof String) { | |
| 441 | 444 | sb.append(XML.escape(object.toString())); | |
| 442 | - } else if (object instanceof JSONObject) { | ||
| 443 | - sb.append(toString((JSONObject)object)); | ||
| 445 | + } else if (object instanceof Number) { | ||
| 446 | + sb.append(object.toString()); | ||
| 447 | + } else if (object instanceof JSONObject) { | ||
| 448 | + sb.append(toString((JSONObject)object)); | ||
| 444 | 449 | } else if (object instanceof JSONArray) { | |
| 445 | 450 | sb.append(toString((JSONArray)object)); | |
| 446 | 451 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -40,7 +40,7 @@ of this software and associated documentation files (the "Software"), to deal | |||
| 40 | 40 | * comparisons of .toString to a string literal are likely to fail. | |
| 41 | 41 | * | |
| 42 | 42 | * @author JSON.org | |
| 43 | - * @version 2011-05-22 | ||
| 43 | + * @version 2011-10-03 | ||
| 44 | 44 | */ | |
| 45 | 45 | public class Test extends TestCase { | |
| 46 | 46 | public Test(String name) { | |
@@ -91,7 +91,11 @@ public void testJSON() throws Exception { | |||
| 91 | 91 | ||
| 92 | 92 | Beany beanie = new Beany("A beany object", 42, true); | |
| 93 | 93 | ||
| 94 | - string = "[0.1]"; | ||
| 94 | + string = "[001122334455]"; | ||
| 95 | + jsonarray = new JSONArray(string); | ||
| 96 | + assertEquals("[1122334455]", jsonarray.toString()); | ||
| 97 | + | ||
| 98 | + string = "[00.10]"; | ||
| 95 | 99 | jsonarray = new JSONArray(string); | |
| 96 | 100 | assertEquals("[0.1]", jsonarray.toString()); | |
| 97 | 101 | ||
@@ -154,16 +158,17 @@ public void testJSON() throws Exception { | |||
| 154 | 158 | jsonarray.toString(4)); | |
| 155 | 159 | assertEquals("<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>", | |
| 156 | 160 | JSONML.toString(jsonarray)); | |
| 161 | + | ||
| 162 | + string = "{\"xmlns:soap\":\"http://www.w3.org/2003/05/soap-envelope\",\"tagName\":\"soap:Envelope\",\"childNodes\":[{\"tagName\":\"soap:Header\"},{\"tagName\":\"soap:Body\",\"childNodes\":[{\"tagName\":\"ws:listProducts\",\"childNodes\":[{\"tagName\":\"ws:delay\",\"childNodes\":[1]}]}]}],\"xmlns:ws\":\"http://warehouse.acme.com/ws\"}"; | ||
| 163 | + jsonobject = new JSONObject(string); | ||
| 164 | + assertEquals("<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:ws=\"http://warehouse.acme.com/ws\"><soap:Header/><soap:Body><ws:listProducts><ws:delay>1</ws:delay></ws:listProducts></soap:Body></soap:Envelope>", | ||
| 165 | + JSONML.toString(jsonobject)); | ||
| 157 | 166 | ||
| 158 | 167 | string = "<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>"; | |
| 159 | 168 | jsonobject = XML.toJSONObject(string); | |
| 160 | 169 | assertEquals("{\"person\": {\n \"lastName\": \"Smith\",\n \"address\": {\n \"postalCode\": \"98765-4321\",\n \"street\": \"12345 Sixth Ave\",\n \"state\": \"CA\",\n \"type\": \"home\",\n \"city\": \"Anytown\"\n },\n \"created\": \"2006-11-11T19:23\",\n \"firstName\": \"Robert\",\n \"modified\": \"2006-12-31T23:59\"\n}}", | |
| 161 | 170 | jsonobject.toString(4)); | |
| 162 | 171 | ||
| 163 | - jsonobject = new JSONObject(beanie); | ||
| 164 | - assertEquals("{\"string\":\"A beany object\",\"BENT\":\"All uppercase key\",\"boolean\":true,\"number\":42,\"x\":\"x\"}" | ||
| 165 | - , jsonobject.toString()); | ||
| 166 | - | ||
| 167 | 172 | string = "{ \"entity\": { \"imageURL\": \"\", \"name\": \"IXXXXXXXXXXXXX\", \"id\": 12336, \"ratingCount\": null, \"averageRating\": null } }"; | |
| 168 | 173 | jsonobject = new JSONObject(string); | |
| 169 | 174 | assertEquals("{\"entity\": {\n \"id\": 12336,\n \"averageRating\": null,\n \"ratingCount\": null,\n \"name\": \"IXXXXXXXXXXXXX\",\n \"imageURL\": \"\"\n}}", | |
| Back | FazBrowse Home | New Git URL |
0 commit comments