public static boolean isJson(String content) {
try {
JSONObject.fromObject(content);
return true;
} catch (Exception e) {
return false;
}
}
本文提供了一个简单的方法来检查字符串是否为有效的JSON格式。通过尝试将字符串转换为JSONObject,如果转换成功则说明字符串是有效的JSON,否则不是。
public static boolean isJson(String content) {
try {
JSONObject.fromObject(content);
return true;
} catch (Exception e) {
return false;
}
}
4674
1271

被折叠的 条评论
为什么被折叠?