Home > Java > JavaBase > body text

Java method to determine whether a string is json

Release: 2019-12-16 16:52:00
Original
4634 people have browsed it

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;
    }
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!