public static List<JSONObject> getJSONObject(String path) {
InputStream input = null;
JSONArray jsonArray = null;
ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
try {
input = new ClassPathResource(path).getInputStream();
byte[] bytes = new byte[1024];
int read = -1;
while ((read = input.read(bytes)) > -1) {
byteArray.write(bytes, 0, read);
}
jsonArray = JSONObject.parseArray(new String(byteArray.toByteArray(), "UTF-8"));
} catch (IOException e) {
e.printStackTrace();
try {
input.close();
byteArray.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
return JSONArray.parseArray(JSONArray.toJSONString(jsonArray), JSONObject.class);
}
Java读取json文件
最新推荐文章于 2023-03-09 14:11:44 发布