@@ -238,7 +238,7 @@ private static boolean parse(XMLTokener x, JSONObject context, String name)
238238 throw x .syntaxError ("Missing value" );
239239 }
240240 jsonobject .accumulate (string ,
241- XML .stringToValue ((String ) token ));
241+ JSONObject .stringToValue ((String ) token ));
242242 token = null ;
243243 } else {
244244 jsonobject .accumulate (string , "" );
@@ -270,7 +270,7 @@ private static boolean parse(XMLTokener x, JSONObject context, String name)
270270 string = (String ) token ;
271271 if (string .length () > 0 ) {
272272 jsonobject .accumulate ("content" ,
273- XML .stringToValue (string ));
273+ JSONObject .stringToValue (string ));
274274 }
275275
276276 } else if (token == LT ) {
@@ -295,49 +295,17 @@ private static boolean parse(XMLTokener x, JSONObject context, String name)
295295 }
296296 }
297297 }
298-
298+
299299 /**
300- * Try to convert a string into a number, boolean, or null. If the string
301- * can't be converted, return the string. This is much less ambitious than
302- * JSONObject.stringToValue, especially because it does not attempt to
303- * convert plus forms, octal forms, hex forms, or E forms lacking decimal
304- * points.
300+ * This method has been deprecated in favor of the
301+ * {@link JSONObject.stringToValue(String)} method. Use it instead.
305302 *
303+ * @deprecated Use {@link JSONObject#stringToValue(String)} instead.
306304 * @param string
307- * A String.
308- * @return A simple JSON value.
305+ * @return JSON value of this string or the string
309306 */
310307 public static Object stringToValue (String string ) {
311- if ("true" .equalsIgnoreCase (string )) {
312- return Boolean .TRUE ;
313- }
314- if ("false" .equalsIgnoreCase (string )) {
315- return Boolean .FALSE ;
316- }
317- if ("null" .equalsIgnoreCase (string )) {
318- return JSONObject .NULL ;
319- }
320-
321- // If it might be a number, try converting it, first as a Long, and then
322- // as a Double. If that doesn't work, return the string.
323- try {
324- char initial = string .charAt (0 );
325- if (initial == '-' || (initial >= '0' && initial <= '9' )) {
326- Long value = new Long (string );
327- if (value .toString ().equals (string )) {
328- return value ;
329- }
330- }
331- } catch (Exception ignore ) {
332- try {
333- Double value = new Double (string );
334- if (value .toString ().equals (string )) {
335- return value ;
336- }
337- } catch (Exception ignoreAlso ) {
338- }
339- }
340- return string ;
308+ return JSONObject .stringToValue (string );
341309 }
342310
343311 /**
0 commit comments