@@ -82,14 +82,18 @@ public static BufferedReader getJSONReader(InputStream is) {
8282 return new JSONReader (is );
8383 }
8484
85+ @ SuppressWarnings ("resource" )
8586 public static Object parse (Object o ) {
8687 if (o instanceof String )
8788 return parse ((String ) o );
8889 if (o instanceof InputStream )
8990 return parse ((InputStream ) o );
9091 if (o instanceof Reader )
9192 return parse ((Reader ) o );
92- return null ;
93+ if (o instanceof URL ) {
94+ return parse ((URL ) o );
95+ }
96+ return new JSONReader (o ).data ;
9397 }
9498
9599 @ SuppressWarnings ("resource" )
@@ -109,6 +113,17 @@ public static Object parse(Reader br) {
109113 return parse (is );
110114 }
111115
116+ @ SuppressWarnings ("resource" )
117+ public static Object parse (URL url ) {
118+ JSUtil .setAjax (url );
119+ try {
120+ return new JSONReader (JSUtil .parseJSON ((InputStream ) url .getContent ())).data ;
121+ } catch (IOException e ) {
122+ return null ;
123+ }
124+ }
125+
126+
112127 /**
113128 * Get an object in the JSON associative array.
114129 *
@@ -169,7 +184,7 @@ public static class JSONReader extends BufferedReader {
169184 public JSONReader (InputStream in ) {
170185 super ((Reader ) (Object ) "" );
171186 // could be buffered
172- data = toObject (/** @j2sNative $in._ajaxData || $in.$in && $in.$in._ajaxData || */
187+ data = toObject (/** @j2sNative $in._jsonData || $in.$in && $in.$in._jsonData || */
173188 null );
174189 if (data == null ) {
175190 String json = (/** @j2sNative $in.str || $in.$in && $in.$in.str || */ null );
@@ -180,7 +195,7 @@ public JSONReader(InputStream in) {
180195 public JSONReader (Reader in ) {
181196 super (in );
182197 // could be buffered
183- data = toObject (/** @j2sNative $in._ajaxData || $in.$in && $in.$in._ajaxData || */
198+ data = toObject (/** @j2sNative $in._jsonData || $in.$in && $in.$in._jsonData || */
184199 null );
185200 }
186201
@@ -189,12 +204,17 @@ public JSONReader(String json) {
189204 data = toObject (JSUtil .parseJSONRaw (json ));
190205 }
191206
207+ public JSONReader (Object jsObject ) {
208+ super ((Reader ) (Object ) "" );
209+ data = toObject (jsObject );
210+ }
211+
192212 @ Override
193213 public void close () {
194214 data = null ;
195215 try {
196216 super .close ();
197- } catch (IOException e ) {
217+ } catch (Throwable e ) {
198218 // ignore, especially if we set $in to a string!
199219 }
200220 }
0 commit comments