读到的json文件不能直接映射成map类型,不过可以通过list来存储一个hashmap
public static List readJsonFile(String fileName) {
String jsonStr = "";
try {
File jsonFile = new File(fileName);
FileReader fileReader = new FileReader(jsonFile);
Reader reader = new InputStreamReader(new FileInputStream(jsonFile), "utf-8");
int ch = 0;
StringBuffer sb = new StringBuffer();
while ((ch = reader.read()) != -1) {
sb.append((char) ch);
}
fileReader.close();
reader.close();
jsonStr = sb.toString();
List<HashMap> listMap = JSONObject.parseArray(jsonStr, HashMap.class);
return listMap;
} catch (IOException e) {
e.printStackTrace();
return null;
}
}