我正在尝试将 json 文件中的数据读取到我的家庭课程中。当我尝试访问数据时,我收到 NPE
Gson gson = new Gson();
try (Reader reader = new FileReader("family.json")) {
Family family = gson.fromJson(reader, Family.class);
System.out.println(family.toString());
} catch (IOException e) {
e.printStackTrace();
}
家庭班
public class Family {
List<Person> people;
人物类
public class Person {
private String firstname;
private String lastname;
json 文件
{ "members" : [
{"firstname":"asdf", "lastname":"asdf"},
{"firstname":"qwer", "lastname":"qwer"},
{"firstname":"fghj", "lastname":"fghj"}
]
}
任何帮助/提示将不胜感激
沧海一幻觉
相关分类