java determines whether the json format is legal
/** * 判断是JsonObject * @param obj * @return */ public static boolean isJsonObject(Object obj) { String content = obj.toString(); try { JSONObject.parseObject(content); if (content.startsWith("{")) { return true; } else { return false; } } catch (Exception e) { return false; } } /** * 判断是JsonArray * @param obj * @return */ public static boolean isJsonArray(Object obj) { String content = obj.toString(); try { JSONArray.parseArray(content); if (content.startsWith("[")) { return true; } else { return false; } } catch (Exception e) { return false; } }php Chinese website, a large number of free
Java introductory tutorials, welcome to learn online!
The above is the detailed content of Java determines whether it is in json format. For more information, please follow other related articles on the PHP Chinese website!