How do I parse JSON objects from a JSONArray?

后端 未结 5 1192
南旧
南旧 2021-01-24 06:18

I have a very large JSON file in the following format:

[{\"fullname\": \"name1\", \"id\": \"123\"}, {\"fullname\": \"name2\", \"id\": \"245\"}, {\"fullname\": \         


        
5条回答
  •  北海茫月
    2021-01-24 06:57

    Your json is a JSONArray, so when you are parsing it, you need to parse it as a JSONArray.

            JSONParser jsonParser = new JSONParser();
            JSONArray a = (JSONArray) jsonParser.parse(new FileReader(src));
            for (Object o : a) {
                // access your object here. 
            }
    

提交回复
热议问题