JSONParser
анализирует все объекты json в данном файле, но я хочу проанализировать объекты json, начиная с 100-й index до конца файла.
Я могу сделать это позже, используя subList
, но если в моем файле json есть 1 миллион объектов json, я не хочу анализировать все, потому что эффективность будет снижена.
public static void readJsonFile() {
JSONParser parser = new JSONParser();
try {
JSONArray a = (JSONArray) parser.parse(new FileReader("D:\\2018-4-21.json"));
for (Object o : a.subList(100,a.size())) {
JSONObject checkIn = (JSONObject) o;
String userId = (String) checkIn.get("UserID");
System.out.print(userId);
String inout = (String) checkIn.get("INOUT");
System.out.print(" " + inout);
String swippedDateTime = (String) checkIn.get("SwippedDateTime");
System.out.print(" " + swippedDateTime);
System.out.println("");
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (org.json.simple.parser.ParseException e) {
e.printStackTrace();
}
}
My Json File
[
{
"UserID": "2",
"INOUT": null,
"SwippedDateTime": "2018-4-23 22:25"
},
{
"UserID": "2",
"INOUT": null,
"SwippedDateTime": "2018-4-23 22:36"
},
{
"UserID": "2",
"INOUT": null,
"SwippedDateTime": "2018-4-23 22:36"
},
{
"UserID": "2",
"INOUT": null,
"SwippedDateTime": "2018-4-23 22:36"
},
{
"UserID": "2",
"INOUT": null,
"SwippedDateTime": "2018-4-23 22:38"
},
{
"UserID": "2",
"INOUT": null,
"SwippedDateTime": "2018-4-23 22:38"
},
{
"UserID": "2",
"INOUT": null,
"SwippedDateTime": "2018-4-23 22:38"
},
{
"UserID": "2",
"INOUT": null,
"SwippedDateTime": "2018-4-23 22:39"
},
{
"UserID": "2",
"INOUT": null,
"SwippedDateTime": "2018-4-23 22:39"
},
{
"UserID": "2",
"INOUT": null,
"SwippedDateTime": "2018-4-23 22:39"
},
{
"UserID": "2",
"INOUT": null,
"SwippedDateTime": "2018-4-23 22:42"
},
{
"UserID": "2",
"INOUT": null,
"SwippedDateTime": "2018-4-23 22:42"
},
{
"UserID": "2",
"INOUT": null,
"SwippedDateTime": "2018-4-23 22:42"
},
{
"UserID": "2",
"INOUT": null,
"SwippedDateTime": "2018-4-23 22:42"
},
{
"UserID": "2",
"INOUT": null,
"SwippedDateTime": "2018-4-23 22:42"
},
{
"UserID": "2",
"INOUT": null,
"SwippedDateTime": "2018-4-23 22:42"
},
{
"UserID": "2",
"INOUT": null,
"SwippedDateTime": "2018-4-23 22:49"
}
]