Import org.json.JSONException; Import Org.json.JSONObject; Import org.dom4j.DocumentException; Import Org.dom4j.DocumentHelper; public class Stringtest {/** * @param args */public static void main (string[] args) {String string1 = "123"; String string2 = "fdgsewe323"; String String3 = "{/" task/":/" 324vfsdfg/"}"; String String4 = "<ww>3243</ww>"; System.out.println ("String1::number" +isnumber (string1)); System.out.println ("String2::number" +isnumber (string2)); System.out.println ("String3::json" +isjson (string3)); System.out.println ("String4::xml" +isxml (String4)); System.out.println ("String1::json" +isjson (string1)); System.out.println ("String2::xml" +isxml (string2)); System.out.println ("String3::number" +isnumber (string3)); System.out.println ("String4::xml" +isxml (String4)); System.out.println ("String1::" +gettype (string1)); System.out.println ("string2::" +gettype (string2)); System.out.println ("String3::" +gettype (String3)); System.out.println ("String4::" +gettype (strING4)); The public static String GetType (string string) {if (Isnumber (string)) return "number"; else if (Isjson (string)) return "Js On "; else if (Isxml (string)) return "XML"; else return "String"; }/** * Infers if the string is a number */public static Boolean Isnumber (string value) {return Isinteger (value) | | isdouble (value);}/** * push Whether the broken string is an integer */public static boolean Isinteger (String value) {try {integer.parseint (value); return true;} catch (Numberfo Rmatexception e) {return false;}} /** * Infers whether the string is a floating-point number */public static Boolean isdouble (string value) {try {double.parsedouble (value), if (Value.contains (". ")) return true; return false; } catch (NumberFormatException e) {return false;}} /** * Inferred if it is a JSON structure */public static Boolean Isjson (String value) {try {new Jsonobject (value)} catch (Jsonexception e) { return false; } return true; }/** * Inferred whether it is an XML structure */public static Boolean Isxml (String value) {try {documenthelper.parsetext (value);} catch (Document Exception e) {return false;} return true; } }
Inferred string strings are numbers, JSON structures, XML structures