javaarraysjsonparsingjsonparser

Parsing in Java don't work with JSONArray


why does my Code not work

JSONArray dataObject = (JSONArray) parse.parse(String.valueOf(informationString));

It always give me the Error Code

java.lang.ClassCastException: class org.json.simple.JSONObject cannot be cast to class org.json.simple.JSONArray (org.json.simple.JSONObject and org.json.simple.JSONArray are in unnamed module of loader 'app')
at org.example.Main.main(Main.java:57)

Solution

  • It seems that you are parsing a JSON object (eg {"a":1,"b":2,...}) which is not a JSON array (eg ["a","b",...]), so it can not be cast to one.