利用json转化,确认字符串是否为json格式,是则返回ture,不是则返回false。
常用于确认请求报文是json还是xml。存在ltts、8583等其他报文场景时,无法用该方法判断
public static boolean isJSON(String str) {
boolean result = false;
try {
Object obj = JSON.parse(str);
result = true;
} catch (Exception e) {
result = false;
}
return result;
}