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!