How do I parse JSON objects from a JSONArray?

后端 未结 5 1190
南旧
南旧 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:49

    you can use Json.simple java api , below is code that can helpful to you

            byte[] bFile = Files.readAllBytes(new File("C:/xyz.json").toPath());
            JSONArray root = (JSONArray) JSONValue.parseWithException(bFile);
            JSONObject rootObj = (JSONObject) root.get(0);
    

    You can get values from JSONObject based on key , it also depends on format of your json as there could be nested json data. So you have to extract data accordingly . Apart from this you can use jackson parser api or GSON as well.

提交回复
热议问题