public static void main(String[] args) {
String path = JsonTest.class.getClassLoader().getResource("students.json").getPath();
String s = readJsonFile(path);
JSONObject jobj = JSON.parseObject(s);
JSONArray student = jobj.getJSONArray("students");//构建JSONArray数组
for (int i = 0 ; i < student.size();i++){
JSONObject key = (JSONObject)student.get(i);
int stuId= (Integer)key.get("stuId");
String stuName= (String)key.get("stuName");
int stuAge= (Integer)key.get("stuAge");
#TODO 数据库操作
System.out.println(stuId);
System.out.println(stuName);
System.out.println(stuAge);
}
}
|