I am in the service and sometimes return something like this:
{ "param1": "value1", "param2": "value2" }
and sometimes getting a refund as follows:
[{ "param1": "value1", "param2": "value2" },{ "param1": "value1", "param2": "value2" }]
How to find out what I get? Both of them evaluate the string when I get getClass (), but if I try to do this:
json = (JSONObject) new JSONParser().parse(result);
in the second case, I get an exception
org.json.simple.JSONArray cannot be cast to org.json.simple.JSONObject
How to avoid this? I just would like to know how to check what I will return to. (The first case sometimes has [] in it, so I cannot make an index, and I would like to make a cleaner way than just checking the first character.
Should there be some method that checks this?
Pixmach
source share