回覆列表
  • 1 # 小紅的甜心

    1、需要json的相關jar包

    2、設定json格式字串:

    String str="{\"student\":[{\"name\":\"leilei\",\"age\":23},{\"name\":\"leilei02\",\"age\":23}]}";

    3、建立相應的類:

    public class StudentList {

    List<Student> student;

    public List<Student> getStudent() {

    return student;

    }

    public void setStudent(List<Student> student) {

    this.student = student;

    }

    }

    public class Student {

    private String name;

    private int age;

    //private StudentClass studentClass;

    public String getName() {

    return name;

    }

    public void setName(String name) {

    this.name = name;

    }

    public int getAge() {

    return age;

    }

    public void setAge(int age) {

    this.age = age;

    }

    }

    4、測試程式

    import java.util.List;

    import org.codehaus.jackson.map.ObjectMapper;

  • 中秋節和大豐收的關聯?
  • 侯耀華真的有資格將郭德綱從侯氏相聲家譜中除名嗎?