public static String getEmail(String id){
BufferedReader reader = null;
String laststr = "";
String email = null;
try {
FileInputStream fileInputStream = new FileInputStream(
PctJsonUtil.class.getResource("/").getFile().toString() + "/email.json");
InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream, "UTF-8");
reader = new BufferedReader(inputStreamReader);
String tempString = null;
while ((tempString = reader.readLine()) != null) {
laststr += tempString;
}
JSONObject jsoncode = JSONObject.parseObject(laststr);
email = String.valueOf(jsoncode.get(id));
reader.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return email;
}
测试json字符串: {“EMAIL”:”值”,”myEmailAccount”:”值”,”myEmailPassword”:”值”}