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

Java method to determine whether a string is json

Release: 2019-12-16 16:52:00
Original
4819 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:
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
Latest Issues
Install JAVA
From 1970-01-01 08:00:00
0
0
0
Unable to install java
From 1970-01-01 08:00:00
0
0
0
Can java be used as the backend of the web?
From 1970-01-01 08:00:00
0
0
0
Is this in Java language?
From 1970-01-01 08:00:00
0
0
0
Help: JAVA encrypted data PHP decryption
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template