发布网友 发布时间:2022-04-26 07:18
共1个回答
热心网友 时间:2022-06-25 04:57
ScriptEngineManager sem = new ScriptEngineManager();ScriptEngine se = sem.getEngineByName("js");String jsonstr = " \r\n [{}]";try { if (!jsonstr.matches("^[\r\n\f\t\\x20]*[\\{\\[][\\s\\S]*")) { throw new ScriptException("必须以{或[开头"); } se.eval("(" + jsonstr + ")"); System.out.println("是json格式");} catch (ScriptException e) { String exp = e.toString().replaceAll(".*\\:(.*)", "$1"); System.err.println(exp.replaceAll("\\(.+(?=at)", ""));}