如何在Java中验证字符串是否为JSON? [英] How to validate a string is JSON or not in Java?
本文介绍了如何在Java中验证字符串是否为JSON?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I've already said, my question is different...question is already asked here, but i want a predefined method in java which checksgiven string is json format or not.
如果没有预定义的方法,则至少告诉一个代码是否检查JSON格式,而不使用try catch块.
if there is no predefined method then at least tell a code which checks JSON Format or not, without using try catch block..
预先感谢...
推荐答案
使用String中的 JSONObject的构造函数
Use JSONObject's constructor from a String
try {
JSONObject o = new JSONObject(yourString);
} catch (JSONException e) {
LOGGER.error("No valid json");
}
这篇关于如何在Java中验证字符串是否为JSON?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文