java判断字符串是否是json字符串
<dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>2.8.9</version> </dependency>
true: 是
public static boolean validate(String jsonStr) { JsonElement jsonElement; try { jsonElement = new JsonParser().parse(jsonStr); } catch (Exception e) { return false; } if (jsonElement == null) { return false; } return jsonElement.isJsonObject(); }
-----------------------有任何问题可以在评论区评论,也可以私信我,我看到的话会进行回复,欢迎大家指教------------------------
(蓝奏云官网如果有地址失效了,可以私信我,后续看到会补充)