本人新手,,,我有个数据结构
{
name = "test1";
age = 6;
address = "address1";
},
{
name = "test2";
age = 6;
address = "address2";
},
{
name = "test3";
age = 6;
address = "address3";
}
我想存到一个ArrayList里要怎么写啊
ArrayList<student> m_student;
是要新建一个student class类吗?

解决方案 »

  1.   

    要建student class类的
    用Jackson大概就是这样的
    ObjectMapper m = new ObjectMapper();
    Student student = m.readValue(json, Student.class);
    然后往你的ArrayList Add
        
      

  2.   

    class Student
    {
    public String Name;
    public int Age;
    public String Address;
    }ArrayList<Student> studentList = new ArrayList<Student>();
    for(int i=0;i<3;i++)
    {
      Student studentInfo = new Student();
      studentInfo.Name = "test"+i;
      studentInfo.Age = 6;
      studentInfo.Address = "address"+i;
      studentList.add(studentInfo);
    }
      

  3.   

    最好用private get,set 养成好习惯
      

  4.   

    student这个类可建可不建,如果不建的话,List里面放Map