Home >Java >JavaBase >Java method to determine whether a string is json

Java method to determine whether a string is json

尚
Original
2019-12-16 16:52:004762browse

Java method to determine whether a string is json

Java method to determine whether a string is json:

json format: {"name":"Michael","age":24,"birthday": "2018-09-09"};

private boolean isjson(String str){
    try {
        JSONObject jsonStr= JSONObject.parseObject(string);
        return  true;
    } catch (Exception e) {
        return false;
    }
}

JSONObject is a class inherited from JSON. When JSONObject.parseObject(result) is called, the parseObject(String text) of the parent class will be called directly. parseObject (String text), parses text into a JSONObject object and returns it.

For more java knowledge, please pay attention to the java basic tutorial column.

The above is the detailed content of Java method to determine whether a string is json. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn