ClassCastException: org.json.simple.JSONArray cannot be cast to org.json.simple.JSONObject

后端 未结 3 653
一向
一向 2021-01-15 15:44

I am trying to parse a son file, and I don\'t know what I\'m doing wrong (of course, I don\'t really know what I\'m doing right, either).

file.json



        
3条回答
  •  不要未来只要你来
    2021-01-15 16:16

    you are getting JSONArray not JsonObject

    JSONParser parser = new JSONParser();
    Object obj = parser.parse(new FileReader("/path/to/file.json"));
    JSONArray json = (JSONArray) obj;
    

    Than loop this and get jsonobject

提交回复
热议问题