超大JSON使用流读取方式避免OOM

书中人 2023年06月15日 651次浏览

超大JSON使用流读取方式避免OOM

private static void test1(String sb) {
		JSONReader jsonReader = new JSONReader(new InputStreamReader(new ByteArrayInputStream(sb.getBytes(StandardCharsets.UTF_8))));
		jsonReader.startArray();
		while (jsonReader.hasNext()) {
			Map readObject = jsonReader.readObject(Map.class);
			System.out.println(readObject.get("a"));
		}
		jsonReader.endArray();
		jsonReader.close();
	}